Database Reference
In-Depth Information
Compiling an ECPG program
In
Chapter 9
,
Communicating PostgreSQL Using LibPQ
, we discussed how to compile
a C program, but compiling ECPG requires one more step. In the
bin
directory of
PostgreSQL, there is an executable program
ecpg
. The
ecpg
program converts a
.pgc
ile and creates a
.c
ile with the same name. In this example, the ECPG program
creates an
ecpg_sample.c
ile from an
ecpg_sample.pgc
ile.
Execute the ECPG program on the ECPG's
sample.pgc
ile to generate the
ecpg_sample.c
ile using the following statement:
$ ecpg ecpg_sample.pgc
List all the iles of the current directory, the
ls
command in Linux and the
dir
command in Windows used to list the iles using the following statements:
$ ls
ecpg_sample.c
ecpg_sample.pgc
This
ecpg_sample.c
ile can be compiled using a standard C compiler using the
following statement:
$ make ecpg_sample
Run the executable
ecpg_sample
ile using the following statement:
$ ./ecpg_sample
The output of
ecpg_sample
is as follows:
$ PostgreSQL Version: PostgreSQL 9.4 on i686-pc-linux-gnu, compiled
by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 32-bit
Export
LD_LIBRARY_PATH
of the
libecpg.so
library:
# export LD_LIBRARY_PATH=/usr/local/pgsql/lib/