I'll assume that you have a working knowledge of general C++ programming. All the examples in this chapter were tested using the GNU C++ compiler and GNU make. libpqxx requires a modern C++ compiler and you may have to upgrade your compiler (or even the OS) if you're running an older version: See the libpqxx website for compatibility information. The libpqxx library is distributed separately from the PostgreSQL distribution: You can find it at http://gborg.postgresql.org/project/libpqxx. Click the Downloads link (look closely, it's there in the upper-right corner of the page) and download the most recent (stable) version. When the download completes, unpack the source tarball with the command:
$ tar -zxvf libpqxx-version.tgz $ cd libpqxx-version
(Be sure to plug the correct version into those commands.)
Now, before you run the configure command, there's one important step that you don't want to forget. The libpqxx configure script examines your computer and creates configuration files that ensure libpqxx will compile and install without any problems. Because libpqxx is a wrapper around PostgreSQL's libpq library, it needs to know where the libpqx header and library files are installed on your system. libpqxx uses the pg_config command to find what it needs. pg_config is a small script that displays the location of various bits of your PostgreSQL installation, and it was custom-created when you installed PostgreSQL. For libpqxx's configure script to work properly, the pg_config script must in your shell's search path. To find out whether you're ready to go, simply type pg_config --help at the command line—if you see a command not found message, you have to find pg_config (it's usually in the same directory that holds psql) and add it to your $PATH environment variable. For example, if you find pg_config in the directory /usr/local/bin, execute the following command to add /usr/local/bin to your search path:
$ export PATH=$PATH:/usr/local/bin
The export command works in the bash and korn shells; if you're using a different shell, check the documentation to find out how to adjust $PATH. Once you know that pg_config is in your search path, do the usual configure/make/make install three-step:
$ ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... gawk ... $ make Making all in include make[1]: Entering directory '/usr/local/src/libpqxx-2.3.0/include' Making all in pqxx make[2]: Entering directory '/usr/local/src/libpqxx-2.3.0/include/pqxx' ... $ make install Making install in include make[1]: Entering directory '/usr/local/src/libpqxx-2.3.0/include' Making install in pqxx make[2]: Entering directory '/usr/local/src/libpqxx-2.3.0/include/pqxx' make[3]: Entering directory '/usr/local/src/libpqxx-2.3.0/include/pqxx' ...
After the make (and make install) has finished, you have a new set of #include files, some new documentation, and a new library to link against. If you chose the default prefix when you configured libpqxx (that is, if you did not include a --prefix=location argument), you'll find the header files in /usr/local/include/pqxx, the object library in /usr/local/lib, and the documentation in ./doc (the documentation isn't copied anywhere—it stays in the directory where you unpacked the source tarball).