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

> NLD $SYSTEM.SYSTEM.CRTLMAIN MYOBJ -o MYEXEC &
-l ZTLHSRL -l ZRWSLSRL -l ZCPLSRL -l ZCRTLSRL &
-l ZCRESRL
2. The specified nld flags link a VERSION2 OSS C program:
> NLD $SYSTEM.SYSTEM.CRTLMAIN MYOBJ -o MYEXEC &
-l ZTLHSRL -l ZRWSLSRL -l ZCPLSRL &
-l ZOSSHSRL -l ZCRTLSRL -l ZCRESRL &
-l ZOSSKSRL -l ZOSSFSRL -l ZSECSRL &
-l ZI18NSRL -l ZICNVSRL -l ZOSSESRL &
-l ZINETSRL -l ZSTFNSRL
3. A simplified version of the previous example:
> NLD $SYSTEM.SYSTEM.CRTLMAIN MYOBJ -o MYEXEC &
-OBEY $SYSTEM.SYSTEM.LIBCOBEY &
-l ZTLHSRL -l ZRWSLSRL -l ZCPLSRL
4. Linking with the ld linker and the VERSION3 Standard C++ Library (the default beginning
library beginning with G06.20):
> LD $SYSTEM.SYSTEM.CCPPMAIN MYOBJ -o MYEXEC &
-OBEY $SYSTEM.SYSTEM.LIBCOBEY -l ZSTLSRL
5. Compiling PIC (Position-Independent Code) using the default 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 ld 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:
nmc / in NC, out NLST / NDLL; shared
== Compile NC with shared (as a DLL); linkfile is PIC
nmc / in MC, out MLST / MOBJ; call_shared
== Compile MC module with call_shared; linkfile is PIC
ld / out LLST / mobj $SYSTEM.SYSTEM.CCPPMAIN -obey &
$SYSTEM.SYSTEM.LIBCOBEY -libvol $myvol.svol -lib NDLL &
-o MEXE
== Build MEXE, specifying CCPPMAIN (CRE component).
== LIBCOBEY specifies standard SRLs to be searched.
298 Compiling and Linking TNS/R Native C and C++ Programs