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 COBOL—523627-004
15-7
Compiling Embedded SQL C/C++ Programs With
Module Definition Files
1. Create the C or C++ source files that contain embedded SQL statements
(sqlprog.sql).
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 -m sqlprog.m
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 module definition file. The
preprocessor options (-x or -m) and the SQLMX_PREPROCESSOR_VERSION=800
environment variable indicate to the preprocessor that you are compiling your
program with module definition files. For more information on setting the
preprocessor options, see Module Management Behavior on page 17-7.
3. The preprocessor produces two files: a modified (annotated) C source file
(sqlprog.c in C or sqlprog.cpp in C++) that contains the C and SQL CLI
translations of embedded SQL statements and the module definition file
(sqlprog.m).
4. Compile the annotated C/C++ source file by using the c89 compiler (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 ELF object file, sqlprog.o.
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 the application’s module definition file by using the SQL/MX compiler
(mxcmp). See Running the SQL/MX Compiler on page 15-26 and Compiling a
Module Definition File on page 15-31.
mxcmp sqlprog.m