C/C++ Programmer's Guide (G06.25+)
Compiler Pragmas
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
13-85
SHARED
SHARED
The SHARED pragma directs the native C and C++ compilers to generate shared code,
which is PIC (Position-Independent Code) and to invoke the ld or eld linker to create
a PIC library file, or a dynamic-link library (DLL).
Compare the action of SHARED with that of the two related pragmas:
•
CALL_SHARED directs the compiler to generate PIC.
•
NON_SHARED directs the compiler to generate a non-PIC loadfile that cannot be
shared and cannot access PIC files.
The pragma default settings are:
Usage Guidelines
•
On Guardian, the SHARED pragma can appear only on the RUN command line for
CCOMP, CPPCOMP, NMC, or NMCPLUS. On OSS, the -Wshared option can
appear only on the command line for the c89 utility.
•
The default behavior of SHARED is to invoke the eld or ld linker and to produce a
PIC library file (a DLL).
°
On Guardian, if you specify both SHARED and RUNNABLE, the compiler issues
an error and terminates.
°
On OSS, if you specify both -c and -Wshared, the compiler issues an error
and terminates.
•
If you specify CPPONLY or SYNTAX with the SHARED pragma, linking does not
occur because it is prevented by the additional pragmas.
•
For complete information about programming with DLLs and linker options for
DLLS, see the:
°
DLL Programmer’s Guide for TNS/R Systems
°
DLL Programmer’s Guide for TNS/E Systems
SHARED
SYSTYPE GUARDIAN SYSTYPE OSS
TNS C compiler N.A. N.A.
G-series TNS c89 utility N.A. N.A.
TNS/R native C and C++ compilers NON_SHARED NON_SHARED
Native c89 utility TNS/R code:
NON_SHARED
TNS/E code:
CALL_SHARED
TNS/R code:
NON_SHARED
TNS/E code:
CALL_SHARED
TNS/E native C and C++ compilers CALL_SHARED CALL_SHARED