无法在 g++ 中链接 libpqxx
MacOS 12.2.2、clang 13.0.0、XCode 开发者工具已安装。 libpqxx 是随自制程序一起安装的,可以通过 include 找到,但链接器找不到该库。
> g++ main.cpp -lpq -lpqxx -I/opt/homebrew/include -std=c++2a
ld: library not found for -lpq
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是main.cpp
#include <iostream>
#include <pqxx/pqxx>
using namespace std;
using namespace pqxx;
int main(int argc, char* argv[]) {
try {
connection C("dbname = testdb user = pgtest password = pgtest \
hostaddr = 127.0.0.1 port = 5432");
if (C.is_open()) {
cout << "Opened database successfully: " << C.dbname() << endl;
} else {
cout << "Can't open database" << endl;
return 1;
}
C.close ();
} catch (const std::exception &e) {
cerr << e.what() << std::endl;
return 1;
}
}
MacOS 12.2.2, clang 13.0.0, XCode developer tools are installed. libpqxx was installed with the homebrew and can be found with include, but the linker cannot find the library.
> g++ main.cpp -lpq -lpqxx -I/opt/homebrew/include -std=c++2a
ld: library not found for -lpq
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is main.cpp
#include <iostream>
#include <pqxx/pqxx>
using namespace std;
using namespace pqxx;
int main(int argc, char* argv[]) {
try {
connection C("dbname = testdb user = pgtest password = pgtest \
hostaddr = 127.0.0.1 port = 5432");
if (C.is_open()) {
cout << "Opened database successfully: " << C.dbname() << endl;
} else {
cout << "Can't open database" << endl;
return 1;
}
C.close ();
} catch (const std::exception &e) {
cerr << e.what() << std::endl;
return 1;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论