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

Table Of Contents
Compiling and Linking TNS/R Native C and C++
Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
16-13
Linking a TNS/R Module
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 on page 13-12
Pragma NON_SHARED on page 13-67
Pragma SHARED on page 13-86
Example of compiling and linking PIC using ld in Examples on page 16-17
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.
Some of the code configured in the system library for TNS processes is packaged in
SRLs for TNS/R native processes. For example, the TNS/R C run-time library, the
TCP/IP sockets library, the Tools.h++ class library, and much of the OSS API are
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.