next up previous contents index
Next: Assignment to Program Variables Up: Programming Interfaces Previous: C++ (LIBPQ++)

  
Compiling Programs

The interfaces discussed so far have been based on C or C++. Each interface requires certain include and library files to generate an executable version of the program.

Interface include files are typically installed in /usr/local/pgsql/include. The compiler flag -I is needed to ensure that the compiler searches the specified directory for include files --for example, -I/usr/local/pgsql/include.

Interface libraries are typically installed in /usr/local/pgsql/lib. The compiler flag -L is needed to ensure that the compiler searches the directory for library files --for example, -L/usr/local/pgsql/lib.

The compiler flag -l is needed for the compiler to link to a specific library file. To link to libpq.a or libpq.so, the flag -lpq is needed. Because the -l flag knows that the file begins with lib, -llibpq is not correct--just -lpq.

The commands to compile myapp for various interfaces are listed below:

LIBPQ 
cc -I/usr/local/pgsql/include -o myapp myapp.c -L/usr/local/pgsql/lib -lpq
LIBPGEASY 
cc -I/usr/local/pgsql/include -o myapp myapp.c -L/usr/local/pgsql/lib -lpgeasy
ECPG 
ecpg myapp.pgc 
cc -I/usr/local/pgsql/include -o myapp myapp.c -L/usr/local/pgsql/lib -lecpg
LIBPQ ++
cc++ -I/usr/local/pgsql/include -o myapp myapp.cpp -L/usr/local/pgsql/lib -lpq++
Notice that each interface has its own library. ECPG requires the ecpg preprocessor to be run before compilation. LIBPQ++ requires the use of a different compiler. 


next up previous contents index
Next: Assignment to Program Variables Up: Programming Interfaces Previous: C++ (LIBPQ++)
Bruce Momjian
2001-05-09