Undefined reference to PQfinish even though libraries etc. are included

1.9k views Asked by At

I'm trying to compile a C++ application using libpq. On my Debian it compiles fine with the following command:

g++ -I /usr/include/postgresql/ -L /usr/lib/postgresql/9.3/lib/ -lpq -o test test.cpp

On my Ubuntu I get the following error:

undefined reference to 'PQfinish'

I've included link to postgresql headers and libraries and used the -lpq. What am I missing?

1

There are 1 answers

1
Mike Seymour On BEST ANSWER

Move -lpq to the end of the command line.

Linking is done in the order specified, and objects are only taken from libraries if they are needed to resolve symbols at that point. So each library has to come after any other object that needs it.