35.10. Processing Embedded SQL Programs
Now that you have an idea how to form embedded SQL C programs, you probably want to know how to compile them. Before compiling you run the file through the embeddedSQLC preprocessor, which converts theSQL 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 theSQL command using thelibpq interface, and put the result in the arguments specified for output.
ecpg prog1.pgc
The preprocessed file can be compiled normally, for example:
cc -c prog1.c
To link an embedded SQL program, you need to include thelibecpg
library, like so:
cc -o myprog prog1.o prog2.o ... -lecpg
Again, you might have to add an option like-L/usr/local/pgsql/lib
to that command line.
You can usepg_config
orpkg-config
with package namelibecpg
to get the paths for your installation.
If you manage the build process of a larger project usingmake, it might be convenient to include the following implicit rule to your makefiles:
ECPG = ecpg%.c: %.pgc $(ECPG) $<
The complete syntax of theecpg
command is detailed inecpg.
Theecpg library is thread-safe by default. However, you might need to use some threading command-line options to compile your client code.