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

Table Of Contents
Compiling and Linking TNS/E Native C and C++
Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
17-17
Linking a TNS/E Module
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);
return 0;
}
Library for DLL (file name NC):
export$ int getnum()
{
return 31;
}
Compiler and Linker Commands:
CCOMP / in NC, out NLST / NDLL; shared
== Compile NC with shared (as a DLL); linkfile is PIC
CCOMP / in MC, out MLST / MOBJ; call_shared
== Compile MC module with call_shared; linkfile is PIC
ELD / out LLST / mobj $SYSTEM.SYSTEM.CCPLMAIN &
-libvol $myvol.svol -lib NDLL &
-o MEXE
== Build MEXE, specifying CCPLMAIN (CRE component).