【问题标题】:Problem compiling program with pqxx使用 pqxx 编译程序时出现问题
【发布时间】:2011-03-13 12:24:00
【问题描述】:

我正在尝试使用 pqxx 编译一个非常简单的程序(什么都不做的示例),但无法做到。 这是“程序”:

$ cat xx.cpp

#include <pqxx/pqxx>
using namespace pqxx;


int main() 
{
    connection conn("dbname=dout1");
    return 0;
}

我曾经尝试用 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

消息返回:

/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

如果我喜欢:

$ g++ -I /usr/local/include/pqxx -L /usr/local/lib/ -l pqxx -l pq xx.cpp

返回:

/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

考虑:

$ 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

我真的不知道还能做什么,因为:

 # 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

路易斯

【问题讨论】:

    标签: c++ postgresql g++ libpqxx


    【解决方案1】:

    在与 pqxx 作者 Jeroen T. Vermeulen 交换电子邮件后,我设法编译了“程序”。 想法是将xx.cpp 放在-lpqxx -lpq 之前 所以,整个命令是:

    g++ -I /usr/local/include/pqxx/ -L /usr/local/lib/ -I /usr/local/pgsql/include/ -L /usr/local/pgsql/lib/ xx.cpp -lpqxx  -lpq
    

    现在可以了。

    【讨论】:

    • 即使我得到了未定义的引用,在我的情况下,我正在使用 code::blocks。你有什么解决办法或想法吗?
    • 如果你使用 g++ 会发生什么?
    【解决方案2】:

    在这里使用一个简单的 g++ -lpqxx xx.cpp 对我有用,所以它看起来非常像一个损坏的安装。请注意,您不需要与 libpq 链接,因为如果您使用共享对象,libpqxx 会为您处理。

    检查您没有将 libpqxx 库安装在不同的位置,例如 /usr/lib、/usr/local 和 /usr/local/pgsql/lib。

    【讨论】:

    • 感谢您的帮助,但问题不是您提到的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-08
    相关资源
    最近更新 更多