可以使用Bazel构建Libpqxx时使用Linkopts

发布于 2025-02-07 15:51:47 字数 1922 浏览 3 评论 0原文

我正在尝试将Bazel与 libpqxx ,它没有本机巴泽尔支持。我没有尝试编写自己的构建文件,而是使用 prure_foreign_cc cmake() 。当我尝试将其添加为CC_Binary的依赖关系时,它可以看到所有标题,但无法运行程序。

当本地安装时,GCC需要库-LPQXX -LPQ(C ++和C绑定)。在本地,所有命令都可以正常工作:例如:g ++ -l/usr/local/lib -lpqxx -lpq foo.cpp其中/usr/usr/local/lib是安装库的位置。我无法在巴泽尔复制这种行为。

我可以看到Bazel-bin中有一个libpqxx-7.7.a文件,但是添加了“ $(Bazel Info Bazel-bin)/workspace/libpqxx-7.7.a”中的路径。为-lpqxx 找不到库。

丢弃链接选项会产生

建筑的未定义符号ARM64:

“ _ asn1_string_get0_data”,从: _pgtls_verify_peer_name_matches_certificate_guts in libpq.a(fe-secure-openssl.o) “ _asn1_string_length”,从: _pgtls_verify_peer_name_matches_certificate_guts in libpq.a(fe-secure-openssl.o) “ _bio_clear_flags”,从: _my_sock_write在libpq.a(fe-secure-openssl.o) _my_sock_read在libpq.a(fe-secure-openssl.o)

我认为这是一个链接错误。我是C ++的新手,并且正在试图将Cmakelists转换为与Bazel合作。我在哪里弄错了我的cmake?

工作区

http_archive(
    name = "libpqxx",
    url = "https://github.com/jtv/libpqxx/archive/refs/heads/master.zip",
    build_file_content = _ALL_CONTENT,
    strip_prefix = "libpqxx-master",
)

构建

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

cmake(
    name = "pqxx",
    cache_entries = {
        "DPostgreSQL_ROOT=": "/Library/PostgreSQL/14", 
        "DSKIP_BUILD_TEST": "on"
    },
    lib_source = "@libpqxx//:all_srcs",
    visibility = ["//visibility:public"],
    out_static_libs = ["libpqxx-7.7.a"],
    targets = ["pqxx"]
)


cc_binary(
    name = "database_tester",
    srcs = ["database_access.cpp"],
    deps = [
          ":pqxx",
      ],
)

I am trying to use Bazel with libpqxx, which does not have native Bazel support. Rather than trying to write my own BUILD file, I am using rules_foreign_cc cmake() to translate the provided CMakeLists.txt, and this builds a library named pqxx and links a static library libpqxx-7.7.a. When I try to add this as a dependency to a cc_binary, it is able to see all the headers, but is not able to run the program.

When installed locally, gcc requires the libraries -lpqxx -lpq (the C++ and C bindings). Locally, all the commands work fine: For example: g++ -L/usr/local/lib -lpqxx -lpq foo.cpp where /usr/local/lib is where the library was installed. I cannot duplicate this behavior in Bazel.

I can see that there is a libpqxx-7.7.a file in bazel-bin, but adding the path from "$(bazel info bazel-bin)/workspace/libpqxx-7.7.a" throws a error: ld: library not found for -lpqxx.

Leaving the link options out produces

Undefined symbols for architecture arm64:

"_ASN1_STRING_get0_data", referenced from:
_pgtls_verify_peer_name_matches_certificate_guts in libpq.a(fe-secure-openssl.o)
"_ASN1_STRING_length", referenced from:
_pgtls_verify_peer_name_matches_certificate_guts in libpq.a(fe-secure-openssl.o)
"_BIO_clear_flags", referenced from:
_my_sock_write in libpq.a(fe-secure-openssl.o)
_my_sock_read in libpq.a(fe-secure-openssl.o)

which I believe is a linking error. I am new to C++, and am trying to translate the CMakeLists to work with Bazel. Where am I building my cmake wrong?

WORKSPACE

http_archive(
    name = "libpqxx",
    url = "https://github.com/jtv/libpqxx/archive/refs/heads/master.zip",
    build_file_content = _ALL_CONTENT,
    strip_prefix = "libpqxx-master",
)

BUILD

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

cmake(
    name = "pqxx",
    cache_entries = {
        "DPostgreSQL_ROOT=": "/Library/PostgreSQL/14", 
        "DSKIP_BUILD_TEST": "on"
    },
    lib_source = "@libpqxx//:all_srcs",
    visibility = ["//visibility:public"],
    out_static_libs = ["libpqxx-7.7.a"],
    targets = ["pqxx"]
)


cc_binary(
    name = "database_tester",
    srcs = ["database_access.cpp"],
    deps = [
          ":pqxx",
      ],
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南巷近海 2025-02-14 15:51:47

看来您尝试将静态libpq链接到二进制文件。在这种情况下,您需要提供所有libpq取决于的静态液体。

根据错误日志,链接器无法求解openssl函数。因此,请确保您已在系统上安装了openssl,并将其静态lib作为deps提供给cc_binary

It seems that you tried to link the static libpq to your binary. In that case, you need to provide all static libs which libpq depends.

According to the error log, the linker can't solve openssl functions. So make sure you have installed openssl on your system and provide its static lib to cc_binary as deps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文