LINK - linking multi-segment C programs.

This explain file describes how to link a multi-segment program written entirely in C (and assembler that conforms with C conventions). For programs that mix C code with another high level language, see "expl nsc mix".

By default, the command for compiling C programs produces a run-unit. If you want to create an OM, use the command's FOrmat= option. OM's produced in this way can be linked with LKED.

LKED Input:

Input to LKED should include the following:

Create_Reference -Symref C$PROGRAM
Create_Heaps -Data 64k
Report -Map Detail_Level_2

The Generate_Run_Unit instruction should include the option

-Entry C$ENTRY

in addition to any other options desired. The Library directive should include the options

-No_System -Language C

The LKED input should also contain an "Include" directive for the program, and whatever other instructions are desired.

Approaches to Linking:

There are three ways of producing a fully linked C program.

  1. Have the C compiler produce a run-unit directly. This is the default.
  2. Have the C compiler link the program and called library routines into a single OM (using the Format=Linked_OM command line option), then call LKED to turn the OM into a run-unit.
  3. Have the C compiler produce an OM of just the compiled routine (using the Format=OM command line option), then call LKED to link this OM with the OM form of the C library.

The previous section described the third approach.

Variations:

For simple cases, a "canned" set of directives is supplied, that can be requested on the "Generate_Run_Unit" directive.

$      lked
$      prmfl   o*,r/c,r,<OM file>
Generate_Run_Unit -Entry C$ENTRY -Language NSC
$      run

Instead of the "-Language C" on the "Library" directive a $PRMFL card and the "-FC" option could be used.

$      select  &system/profile.prod/nsc
$      lked
$      prmfl   cl,r/c,r,&cv00rp/lib.oml NSC library
Generate_Run_Unit -Name OBJECT -Entry C$ENTRY
Library -fc cl -No_System
Create_Reference -Symref C$PROGRAM
Create_Heaps -Data 64k
Software_Stack_Segment 1k
Report -Map Detail_level_2
Include -fc o*
$      prmfl   v*,w,r,<run unit file>
$      prmfl   o*,r/c,r,<input OM file>
Generate_Run_Unit -Entry C$ENTRY 

LD vs. LKED:

C programs may also be linked with LD (described in "expl ld"), provided that the object code is generated in LD format. LD has several advantages over LKED:

The advantages of LKED are:

Notes:

There is documentation in other packages that tell you to specify "-use_Data_Stack" on the LKED Software_Stack_Segment directive. This advice should be ignored when linking a program using NS C, or NS C mixed with other languages. In non-NSC environments there is a potential problem that can be avoided by specifying "-use_Data_Stack". However, the NS C library domain entry code looks after the condition internally, and so it is not a problem. Specifying "-use_Data_Stack" can cause other run time errors and should be avoided for programs using NS C, or mixed lnaguage programs.

See Also:

expl nsc command

expl nsc mix

Copyright © 1996, Thinkage Ltd.