我正在尝试将 C++ 连接到 Postgres。
我最近使用 Homebrew 安装了 libpqxx,如下所示:
brew install libpqxx
然后我用:make DatabaseTest
在文件 DatabaseTest.cpp 上做到了。
我运行了以下简单的程序,遇到了一个奇怪的错误,我不知道该怎么办......
#include <iostream>
#include <pqxx/pqxx>
int main(int, char *argv[])
{
pqxx::connection c("dbname=company user=accounting");
}
我运行 make 它告诉我链接器失败了,这对我来说没有多大意义......有什么想法可能在这里发生吗?抱歉,如果这很简单,自从我完成 C++ 以来已经有一段时间了!
"pqxx::connection_base::init()", referenced from:
pqxx::basic_connection<pqxx::connect_direct>::basic_connection(char const*) in DatabaseTest-bdc916.o
"pqxx::connection_base::close()", referenced from:
pqxx::basic_connection<pqxx::connect_direct>::~basic_connection() in DatabaseTest-bdc916.o
"pqxx::connection_base::connection_base(pqxx::connectionpolicy&)", referenced from:
pqxx::basic_connection<pqxx::connect_direct>::basic_connection(char const*) in DatabaseTest-bdc916.o
"pqxx::connectionpolicy::connectionpolicy(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
pqxx::connect_direct::connect_direct(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in DatabaseTest-bdc916.o
"pqxx::connectionpolicy::~connectionpolicy()", referenced from:
pqxx::connect_direct::~connect_direct() in DatabaseTest-bdc916.o
"vtable for pqxx::connect_direct", referenced from:
pqxx::connect_direct::connect_direct(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in DatabaseTest-bdc916.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [DatabaseTest] Error 1