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

Table 52 Using the Guardian eld Utility to Link DLLs (continued)
You should specify these eld utility flags:If your program uses:
-l UTIL and other DLLs required by the program environmentOSS nlist() function
-l INET and other DLLs required by the program environmentTCP/IP socket library
For more details about the linker, see these manuals:
eld Manual
rld Manual
Examples
1. The specified eld flags link a VERSION2 Guardian C++ program that uses the Tools.h++
class libraries (TLH7) and the Standard C++ Library (CPP2):
> ELD $SYSTEM.SYSTEM.CCPLMAIN MYOBJ -o MYEXEC &
-l TLH7 -l CPPC -l CPP2 -l CRTL &
-l CRE
2. The specified eld flags link a VERSION2 OSS C program:
> ELD $SYSTEM.SYSTEM.CCPLMAIN MYOBJ -o MYEXEC &
-set systype oss &
-l TLH7 -l CPPC -l CPP2 &
-l OSSH -l CRTL -l CRE &
-l OSSK -l OSSF -l SEC &
-l I18N -l ICNV -l OSSE &
-l INET
3. Linking with the eld linker and the VERSION3 Standard C++ Library (the default library):
> ELD $SYSTEM.SYSTEM.CCPLMAIN MYOBJ -o MYEXEC &
-l CPP3 -l CPPC
4. The specified eld flags link a LP64 OSS C program:
> ELD $SYSTEM.SYSTEM.CMAIN64 MYOBJ -o MYEXEC &
-set systype oss &
-l CRTl -l CRE -l OSSK -l OSSF -l SEC &
-l I18N -l ICNV -l OSSE -l INET -l OSSH
5. 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()
{
310 Compiling and Linking TNS/E Native C and C++ Programs