C/C++ Programmer's Guide (G06.27+, H06.08+, J06.03+)

> NMC /IN filec / fileo; RUNNABLE
5. Generating an executable TNS/R native program composed of the modules mod1c, mod2o,
mod3o, and mod4o:
> NMC /IN mod1c / fileo; RUNNABLE, LINKFILE "myfile"
In this example, myfile is a text file containing these names of object files (not source
files):
mod2o
mod3o
mod4o
Linking a TNS/R Module
You need to use a linker to collect and combine object files into a program file (an executable
object file or a loadfile) if you did not instruct the compiler to perform the linking (that is, if you did
not use the RUNNABLE pragma when compiling a single-module program or if you did not use the
RUNNABLE and LINKFILE pragmas when compiling a multiple-module program).
This subsection provides a summary of linking C and C++ programs using the nld utility, the
TNS/R native linker for conventional applications. For complete details about using nld, see the
nld Manual.
The ld utility is the linker for PIC (Position-Independent Code). For more details about PIC and
sharing code, see the:
Pragma CALL_SHARED (page 177)
Pragma NON_SHARED (page 222)
Pragma SHARED (page 237)
Example of compiling and linking PIC using ld in Examples (page 297)
For more details about ld, see the ld Manual.
CRTLMAIN File
The CRTLMAIN file, located in $SYSTEM.SYSTEM, contains initialization code for the TNS/R native
C and C++ run-time libraries. This object file must be linked into C and C++ programs. In many
instances, c89, NMC and NMCPLUS link, compile, and automatically include CRTLMAIN.
You need to explicitly link CRTLMAIN when you run the linker to create a loadfile if the linkfiles
were:
compiled without the RUNNABLE and LINKFILE options when using NMC or NMCPLUS
compiled with the -c, -Wnolink, or -Wnomain option when using c89
The PIC (Position-Independent Code) variant of CRTLMAIN is named CCPPMAIN. On OSS
environment, the PIC variant of crtlmain.o is ccppmain.o.
A similar initialization file for doing fault-tolerant programming, named CRTLNS, also might need
to be linked. The PIC variant is CRTLNS2. On OSS environment, the PIC variant of crtlns.o is
crtlns2.o.
Shared Run-Time Libraries (SRLs)
An SRL contains code present in virtual memory at run time, to be shared by other processes, rather
than code that is linked into object files. An SRL can also contain global data, and each process
using the SRL automatically gets its own run-time copy of the data, called instance data. A process
can use several SRLs.
NOTE: nld supports native SRLs. It does not support the TNS shared run-time library available
to TNS and accelerated programs in the OSS environment. For more details about the TNS SRL,
see the Binder Manual.
294 Compiling and Linking TNS/R Native C and C++ Programs