无法在 g++ 中链接 libpqxx

发布于 2025-01-15 15:57:00 字数 945 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文