Now that you have an idea how to form embedded SQL COBOL programs, you probably want to know how to compile them. Before compiling you run the file through the embedded SQL COBOL preprocessor, which converts the SQL statements you used to special function calls. After compiling, you must link with a special library that contains the needed functions. These functions fetch information from the arguments, perform the SQL command using the libpq interface, and put the result in the arguments specified for output.
The preprocessor program is called ecobpg and is included in a normal PostgreSQL installation. Embedded SQL programs are typically named with an extension .pco. If you have a program file called prog1.pco, you can preprocess it by simply calling:
ecobpg prog1.pco
This will create a file called prog1.cob. If your input files do not follow the suggested naming pattern, you can specify the output file explicitly using the -o option.
The preprocessed file can be compiled normally, following the usage of the compiler.
The generated COBOL source files include library files from the PostgreSQL installation, so if you installed PostgreSQL in a location that is not searched by default, you have to add an option such as -I/usr/local/pgsql/include to the compilation command line.
To link an embedded SQL program, you need to include the libecpg library.
Again, you might have to add an option for library search like -L/usr/local/pgsql/lib to that command line.
If you manage the build process of a larger project using make, it might be convenient to include the following implicit rule to your makefiles:
ECOBPG = ecobpg %.cob: %.pco $(ECOBPG) $<
The complete syntax of the ecobpg command is detailed in "D.12.1 ecobpg".
Currently, ecobpg does not support multi threading.