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

Linking a TNS/E 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 TNS/E native C and C++ programs using the eld
utility, the TNS/E native linker. The eld utility is a linker for PIC (Position-Independent Code). For
more details about PIC and sharing code, see:
Pragma CALL_SHARED (page 177)
Pragma SHARED (page 237)
Example of compiling and linking PIC using eld in Examples (page 297)
For more details about eld, see the eld Manual.
CCPLMAIN File
The CCPLMAIN file, located in $SYSTEM.SYSTEM, contains initialization code for the TNS/E
native C and C++ run-time libraries. This object file must be linked into C and C++ programs. In
many instances, c89, CCOMP and CPPCOMP link, compile, and automatically include CCPLMAIN.
You need to explicitly link CCPLMAIN when you run the linker to create a loadfile if the linkfiles
were:
Compiled without the RUNNABLE and LINKFILE options when using CCOMP or CPPCOMP
Compiled with the -c, -Wnolink, or -Wnomain option when using c89
A similar initialization file for doing fault-tolerant programming, named CRTLNSE, also might need
to be linked. On OSS environment, the file is named crtlnse.o.
NOTE: For programs compiled with the LP64 data model, the name of the main program file is
CMAIN64.
Dynamic-Link Libraries (DLLs)
A DLL contains code present in virtual memory at run time, to be shared by other processes, rather
than code that is linked into object files. A DLL can also contain global data, and each process
using the DLL automatically gets its own run-time copy of the data, called instance data. A process
can use several DLLs.
HP supplies public DLLs; you can create your own public DLLs.
Each process loads its public DLLs at startup from the active ZDLLnnn subvolume. The ZDLLnnn
subvolume, located on $SYSTEM, contains a version of the public DLLs supplied by HP. A node
can have more than one ZDLLnnn subvolume, but only one active (running) ZDLLnnn subvolume.
Some code is automatically provided from the implicit libraries in the SYSnn subvolume. The SYSnn
subvolume, located on $SYSTEM, contains a version of the operating system files for a particular
node. You do not need to link code kept in the implicit libraries.
When you use eld to build an executable program, eld fixes up references to the DLLs that you
have specified. You can also use eld to repeat the fix-up process on an existing program to use
a new version of an DLL or let the rld run-time loader or operating system update the references
when you execute the program.
To create an executable TNS/E native C or C++ program using eld:
1. Specify $SYSTEM.SYSTEM.
2. CCPLMAIN to link to the TNS/E native C and C++ run-time library initialization object code
file.
3. Specify the object code files that you compiled.
Working in the Guardian Environment 307