SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

C/C++ Program Compilation
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
15-4
Compiling Embedded SQL C/C++ Programs With
Embedded Module Definitions
2. Preprocess the application’s embedded SQL source files by using the SQL/MX
C/C++ preprocessor mxsqlc. See Running the SQL/MX C/C++ Preprocessor on
page 15-8.
mxsqlc sqlprog.sql -c sqlprog.c
In this step, set optional module specification strings and moduleCatalog and
moduleSchema default settings by using the -g option. See 15-18 or 15-24.
Although you do not set mxcmp defaults here, if the input source file contains
mxcmp default settings, such as EXEC SQL DECLARE/SET/CONTROL QUERY
DEFAULT statements, they are preprocessed into corresponding module language
statements in the output module definition of the annotated source file.
3. The preprocessor produces a modified (annotated) C source file (sqlprog.c in C
or sqlprog.cpp in C++) that contains the C and SQL call-level interface (CLI)
translations of embedded SQL statements and additional C/C++ source constructs
that represent the module definition. The default behavior creates a single, self-
contained application source file with embedded module definitions.
4. Compile the annotated C/C++ source file by using the c89 compiler (HP NonStop
Open System Services (OSS) environment) or ETK (Windows environment). To
produce an object file:
c89 -c sqlprog.c -o sqlprog.o
Specify the -c option if you do not want c89 to link the program. Otherwise, c89
invokes eld or nld to create an executable file.
See Running the C/C++ Compiler and Linker on page 15-25.
5. The C/C++ compiler produces the object file, sqlprog.o. If you prefer early
detection of SQL compilation errors, you can SQL compile the application’s object
file at this point. During program development, you might want to use the
mxCompileUserModule utility against all the object files rather than against the
executable file. When you SQL compile against the object files, NonStop SQL/MX
does not recompile each module for object files that are linked into more than one
executable file.
6. Link application object files with object libraries to create an executable file. For
TNS/R native compilation, use the nld utility:
nld /usr/lib/crtlmain.o sqlprog.o -o sqlprog.exe -elf \
-set systype oss -set highpin off -set highrequestor on \
-set inspect on -obey /usr/lib/libc.obey \
-set saveabend on \
-Bdynamic -lzcplsrl -lzcrtlsrl -lzcresrl -lzcplosrl \
-lztlhgsrl -lztlhosrl -lzclisrl
7. The linker produces the application’s executable file, sqlprog.exe.
8. SQL compile one, some, or all of the application’s embedded module definitions in
the executable file by using mxCompileUserModule. See Running the