user_0 user_0 - 1 month ago 12
C++ Question

How to solve this compiling error with pqxx under code blocks

After using libpq-fe.h in the past, for a new project I'm starting use pqxx.

So, in the code I include:

#include <pqxx/pqxx>


And I compile. Everything fine.

When I declare:

pqxx::connection p_con;


And I compile, I have errors:

obj/Debug/src/dbfunc.o: In function `pqxx::connect_direct::connect_direct(std::string const&)':
/usr/include/pqxx/connection.hxx:87: undefined reference to `pqxx::connectionpolicy::connectionpolicy(std::string const&)'
/usr/include/pqxx/connection.hxx:87: undefined reference to `vtable for pqxx::connect_direct'
obj/Debug/src/dbfunc.o: In function `pqxx::connect_direct::~connect_direct()':
/usr/include/pqxx/connection.hxx:84: undefined reference to `vtable for pqxx::connect_direct'
/usr/include/pqxx/connection.hxx:84: undefined reference to `pqxx::connectionpolicy::~connectionpolicy()'
obj/Debug/src/dbfunc.o: In function `pqxx::basic_connection<pqxx::connect_direct>::basic_connection()':
/usr/include/pqxx/basic_connection.hxx:61: undefined reference to `pqxx::connection_base::connection_base(pqxx::connectionpolicy&)'
/usr/include/pqxx/basic_connection.hxx:62: undefined reference to `pqxx::connection_base::init()'
obj/Debug/src/dbfunc.o: In function `pqxx::basic_connection<pqxx::connect_direct>::~basic_connection()':
/usr/include/pqxx/basic_connection.hxx:78: undefined reference to `pqxx::connection_base::close()'


A search on google indicates that this is not a library problem.

Infact: a very similar problem, same error, was already solved here: Problem compiling program with pqxx

I don't get how to solve it in code::blocks. Any suggestion?

Software versions:


  • Code::Blocks 13.12

  • Os: Debian 8.2

  • Libpqxx: libpqxx-4.0

  • Compiler used: gcc

  • gcc --version: gcc (Debian 4.9.2-10) 4.9.2



I am relatively new to using code::blocks, so probably I'm missing something :-/

EDIT: As requested the 2 path:


  • /usr/lib/x86_64-linux-gnu/libpq.so

  • /usr/lib/x86_64-linux-gnu/libpq.a


Answer

-lpq, like all -l<libname> options, is a linker option, not a compiler option. By putting it in Compiler settings -> Other options you say you have generated a compile commandline:

g++ -std=c++11 -Wall -fexceptions -g -lpq -Iinclude -c /myfile.cpp -o /myfile.o

Since this is just a compile command no linking is involved and -lpq is ignored, while in your link commandline - which you haven't shown us - no -lpq option will appear.

Take -lpq out of Compiler settings -> Other options and put -lpqxx and -lpq in Linker settings -> Other options. Then -lpqxx -lpq will be passed to to linker, as they need to be.

If the linker complains that -lpqxx is not found, then you need to install libpqxx

Comments