I'm trying to compile a very simple program (sample that does nothing) with pqxx, but cannot do it. Here's the 'program':
$ cat xx.cpp
#include <pqxx/pqxx>
using namespace pqxx;
int main()
{
connection conn("dbname=dout1");
return 0;
}
The command I used to try to compile in C++:
g++ -I /usr/local/include/ -L /usr/local/lib/ -l pqxx -I /opt/postgres_home/include/ -L /opt/postgres_home/lib/ -lpq xx.cpp
Message returned:
/tmp/cc18wMEy.o: In function `pqxx::connect_direct::connect_direct(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
xx.cpp:(.text._ZN4pqxx14connect_directC1ERKSs[pqxx::connect_direct::connect_direct(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x1f): undefined reference to `pqxx::connectionpolicy::connectionpolicy(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
xx.cpp:(.text._ZN4pqxx14connect_directC1ERKSs[pqxx::connect_direct::connect_direct(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x2a): undefined reference to `vtable for pqxx::connect_direct'
/tmp/cc18wMEy.o: In function `pqxx::connect_direct::~connect_direct()':
xx.cpp:(.text._ZN4pqxx14connect_directD1Ev[pqxx::connect_direct::~connect_direct()]+0x13): undefined reference to `vtable for pqxx::connect_direct'
xx.cpp:(.text._ZN4pqxx14connect_directD1Ev[pqxx::connect_direct::~connect_direct()]+0x1f): undefined reference to `pqxx::connectionpolicy::~connectionpolicy()'
/tmp/cc18wMEy.o: In function `pqxx::basic_connection<pqxx::connect_direct>::basic_connection(char const*)':
xx.cpp:(.text._ZN4pqxx16basic_connectionINS_14connect_directEEC1EPKc[pqxx::basic_connection<pqxx::connect_direct>::basic_connection(char const*)]+0x2b): undefined reference to `pqxx::connection_base::connection_base(pqxx::connectionpolicy&)'
xx.cpp:(.text._ZN4pqxx16basic_connectionINS_14connect_directEEC1EPKc[pqxx::basic_connection<pqxx::connect_direct>::basic_connection(char const*)]+0xd6): undefined reference to `pqxx::connection_base::init()'
/tmp/cc18wMEy.o: In function `pqxx::basic_connection<pqxx::connect_direct>::~basic_connection()':
xx.cpp:(.text._ZN4pqxx16basic_connectionINS_14connect_directEED1Ev[pqxx::basic_connection<pqxx::connect_direct>::~basic_connection()]+0x17): undefined reference to `pqxx::connection_base::close()'
collect2: ld returned 1 exit status
If I do like:
$ g++ -I /usr/local/include/pqxx -L /usr/local/lib/ -l pqxx -l pq xx.cpp
Returns:
/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../../x86_64-slackware-linux/bin/ld: cannot find -lpq
collect2: ld returned 1 exit status
Considering:
$ cat /etc/ld.so.conf
/usr/local/lib
/usr/local/pgsql/lib <-- just symlink to /opt/postgres_home/
/opt/postgres_home/lib
/usr/x86_64-slackware-linux/lib
/usr/lib64/seamonkey
/opt/kde3/lib64
/usr/lib64/jre1.6.0_16/lib/amd64
I really don't know what else to do, because:
# ls /opt/postgres_home/lib/libpq*
/opt/postgres_home/lib/libpq.a /opt/postgres_home/lib/libpq.so.5.3
/opt/postgres_home/lib/libpq.so /opt/postgres_home/lib/libpqwalreceiver.so
/opt/postgres_home/lib/libpq.so.5
Luis
After an email exchange with pqxx author Jeroen T. Vermeulen, I could manage to compile the 'program'.
The idea was to place xx.cpp
before -lpqxx -lpq
So, the entire command is:
g++ -I /usr/local/include/pqxx/ -L /usr/local/lib/ -I /usr/local/pgsql/include/ -L /usr/local/pgsql/lib/ xx.cpp -lpqxx -lpq
It works now.
Works for me here with a simple g++ -lpqxx xx.cpp, so it terribly looks like a broken installation. Note that you don't need to link with libpq, as libpqxx with take care of that for you if you are using shared objects.
Check that you don't have the libpqxx library installed in different places, like /usr/lib, /usr/local, and /usr/local/pgsql/lib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With