c++ - 如何在代码块下使用pqxx解决这个编译错误

标签 c++ gcc codeblocks

在过去使用 libpq-fe.h 后,对于一个新项目,我开始使用 pqxx。

所以,在我的代码中包括:

#include <pqxx/pqxx>

我编译了。一切都很好。
当我声明时:

pqxx::connection p_con;

我编译时出现错误:

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()'

谷歌搜索表明这不是库问题。
事实上:一个非常相似的问题,同样的错误,已经在这里解决了:Problem compiling program with pqxx

我不知道如何在 code::blocks 中解决它。有什么建议吗?

软件版本:

  • 代码:: block 13.12
  • 操作系统:Debian 8.2
  • Libpqxx:libpqxx-4.0
  • 使用的编译器:gcc
  • gcc --版本:gcc (Debian 4.9.2-10) 4.9.2

我对使用 code::blocks 比较陌生,所以可能我错过了一些东西:-/

编辑:根据要求,2条路径:

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

最佳答案

-lpq ,就像所有-l<libname> options,是链接器选项,而不是 一个编译器选项。通过将其放入编译器设置 -> 其他选项 你说你已经生成了一个编译命令行:

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

由于这只是一个编译命令,不涉及链接,-lpq被忽略, 在您的 link 命令行中 - 您没有向我们展示 - 否 -lpq选项 将会出现。

-lpq编译器设置 -> 其他选项并输入 -lpqxx-lpq链接器设置 -> 其他选项中。然后-lpqxx -lpq将被传递到 链接器,因为它们需要。

如果链接器提示 -lpqxx没有找到,那么需要安装 libpqxx

关于c++ - 如何在代码块下使用pqxx解决这个编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33481643/

相关文章:

c - "watches"调试工具上的错误值

Linux 上的 Codeblocks 调试不起作用

c++ - 没有用于调用构造函数的匹配函数 (c++)

c++ - 动态库问题 : dlsym() failing to find smbol

c++ - 使用 AVX 异或两个 zmm(512 位)寄存器

用优化编译得到一个错误的条件

c++ - 如何查看到控制台的长 C++ 输出(仅显示结束部分)

c++ - 如何使用 STL 将数组转换为 vector

c++ - "vector iterator + offset out of range"断言有用吗?

linux - 如何将 "-fstack-protector-all"添加到 makefile?