informix
INFORMIX-ESQL/C Programmer's Manual
Compiling Programs

Compiling an INFORMIX-ESQL/C Program

You use the esql command to compile your ESQL/C program. The esql command passes your ESQL/C source file to the ESQL/C preprocessor and to the C compiler. It passes along options that are specific to both the ESQL/C preprocessor and the C compiler to preprocess, compile, and link your ESQL/C program.

ESQL/C Preprocessor

To preprocess, compile, and link a program that contains ESQL/C statements, you must pass it through the ESQL/C preprocessor. You use the esql command to run the preprocessor on your ESQL/C source file and create an executable file. The esql command follows these steps to carry out the conversion:

The esql command processor is installed as part of the ESQL/C product. Before you use esql, make sure that:

For a detailed explanation of the syntax of the esql command, see Using the esql Command.

Warning: Always link your ESQL/C program with the esql program. The lists of libraries that Informix uses can change between releases. Linking with esql assures that your ESQL/C program will link correctly with Informix libraries.

The C code that the ESQL/C preprocessor generates might change from one release of the product to the next. Therefore, do not design ESQL/C programs that depend on how Informix implements the functionality and features of the product in the C code that the ESQL/C preprocessor generates. Instead, develop your programs with the functionality and features of the product that this manual describes.

C Preprocessor and Compiler

The esql command does not itself compile and link the ESQL/C program. The esql command translates ESQL/C code to C code and then calls the C compiler to compile and link the C code. The C preprocessor preprocesses the C language preprocessing directives. The C compiler performs the compilation, and it also calls a link editor to link the C object files.

Your ESQL/C source file contains commands for the C preprocessor (directives of the form #directive). When you use the default order of compilation, these C directives have no effect on ESQL/C statements but take effect in the usual way when the C compiler processes the source file.

If you choose to run the C preprocessor on the ESQL/C source file before the ESQL/C preprocessor, you can use the C language #define and typedef directives to define ESQL/C host variables. For more information, see Running the C Preprocessor Before the ESQL/C Preprocessor.

The C compiler takes the following actions:

For information about command-line options that affect the compilation and linking steps, see Specifying a Particular C Compiler and Syntax of Additional Options for Windows.

Default Compilation Order

Once you have created an ESQL/C program file, you run the esql command on that file. By default, the ESQL/C preprocessor runs first and translates the embedded SQL statements in the program into ESQL/C function calls that communicate with the database server. The ESQL/C preprocessor produces a C source file and calls the C compiler. The C compiler then preprocesses and compiles your source file and links any other C source file, object file, or library file the same way as any other C program. If esql does not encounter errors in one of these steps, it generates an executable file. You can run the compiled ESQL/C program as you would any C program. When the program runs, it calls the ESQL/C library procedures; the library procedures set up communications with the database server to carry out the SQL operations.

Figure 2-1 illustrates the process by which an ESQL/C program becomes an executable program.

Figure 2-1
Relationship Between INFORMIX-ESQL/C and C

Important: Keep in mind that with the default order of compilation, esql handles ESQL/C preprocessor directives before it calls the C compiler. Therefore, the ESQL/C directives take effect before the C compiler performs any preprocessing. You cannot access ESQL/C definitions within C preprocessor directives, nor can you use the C preprocessor to perform conditional compilation of ESQL/C statements.

Running the C Preprocessor First

ESQL/C allows you change the default order of processing when you compile your ESQL/C program. ESQL/C allows you to run the C preprocessor on the ESQL/C source file first, and then pass that file to the ESQL/C preprocessor. This feature enables your ESQL/C program to access variables made available by C preprocessor directives. For more information on this option, see Running the C Preprocessor Before the ESQL/C Preprocessor.


INFORMIX-ESQL/C Programmer's Manual, Version 9.21
Copyright © 1999, Informix Software, Inc. All rights reserved