C/C++ Programmer's Guide (G06.25+)

Compiling and Linking TNS/E Native C and C++
Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
17-16
Linking a Module
For more information about the linker, see the following manuals:
eld Manual
rld Manual
Examples
1. The specified eld flags link a VERSION2 Guardian C++ program that uses the
Tools.h++ class libraries (ZTLH7DLL) and the Standard C++ Library (ZCPP2DLL):
> ELD $SYSTEM.SYSTEM.CCPLMAIN MYOBJ -o MYEXEC &
-l ZTLH7DLL -l ZCPPCDLL -l ZCPP2DLL -l ZCRTLDLL &
-l ZCREDLL
2. The specified eld flags link a VERSION2 OSS C program:
> ELD $SYSTEM.SYSTEM.CCPLMAIN MYOBJ -o MYEXEC &
-l ZTLH7DLL -l ZCPPCDLL -l ZCPP2DLL &
-l ZOSSHDLL -l ZCRTLDLL -l ZCREDLL &
-l ZOSSKDLL -l ZOSSFDLL -l ZSECDLL &
-l ZI18NDLL -l ZICNVDLL -l ZOSSEDLL &
-l ZINETDLL
3. Linking with the eld linker and the VERSION3 Standard C++ Library (the default
library):
> ELD $SYSTEM.SYSTEM.CCPLMAIN MYOBJ -o MYEXEC &
-l ZCPP3DLL -l ZCPPCDLL
4. Compiling PIC (Position-Independent Code) using the default TNS/E native C++
dialect (VERSION3 ). The example program (MEXE) uses a DLL (named NDLL)
compiled from a library file named NC, which contains the getnum() function.
MEXE imports getnum() and prints the result (31).
Note the use of the import$ and export$ keywords, the SHARED pragma (to
compile the library) and CALL_SHARED pragma (to compile the main module), and
the eld and rld utilities (the PIC linker and loader). The result is a dynamic-link
library (DLL) named NDLL:
Source file (named MC):
import$ extern int getnum();
int main()
{
int x = -99;
x = getnum();
printf (“x was -99; is now %d”, x);
TCP/IP socket library -l ZINETDLL and other DLLs required by the program
environment
Table 17-6. Using the Guardian eld Utility to Link DLLs (page 2 of 2)
If your program uses: You should specify these eld utility flags: