Reputation: 1
I am trying to build libpqxx with Bazel. But I am having two different issues:
undefined reference to PQ
- more details below).Machine: Linux 6.1.0-18-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64 GNU/Linux
I already installed:
sudo apt install postgresql postgresql-contrib
sudo apt-get install -y libpq-dev
My WORKSPACE file:
http_archive(
name = "rules_foreign_cc",
sha256 = "62e364a05370059f07313ec46ae4205af23deb00e41f786f3233a98098c7e636",
strip_prefix = "rules_foreign_cc-ae4ff42901354e2da8285dac4be8329eea2ea96a",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/ae4ff42901354e2da8285dac4be8329eea2ea96a.tar.gz", # v 0.7.1
)
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies(
register_built_tools = True,
)
new_git_repository(
name = "pqxx",
build_file = "//:libpqxx.BUILD",
commit = "9d2a459f76f52ea0df7b9b306b27fba84bb82e5f",
remote = "https://github.com/jtv/libpqxx",
)
libpqxx.BUILD:
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
package(
default_visibility = ["//visibility:public"],
)
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
visibility = ["//:__pkg__"],
)
cmake(
name = "pqxx",
build_args = [
"--verbose",
],
cache_entries = {
"CMAKE_C_FLAGS": "-fPIC",
"CMAKE_STATIC_LINKER_FLAGS": "-lpqxx -lpq",
"BUILD_SHARED_LIBS": "off",
"PostgreSQL_TYPE_INCLUDE_DIR": "/usr/include/postgresql",
"PostgreSQL_INCLUDE_DIR": "/usr/include/postgresql",
"PostgreSQL_LIBRARY": "/usr/lib/x86_64-linux-gnu/libpq.so",
},
lib_source = "@pqxx//:all_srcs",
visibility = ["//visibility:public"],
out_static_libs = ["libpqxx.a"],
targets = ["pqxx"],
)
The error is:
...
[100%] Linking CXX static library libpqxx-7.9.a
cd /home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/sandbox/linux-sandbox/79/execroot/__main__/bazel-out/k8-fastbuild/bin/external/pqxx/pqxx.build_tmpdir/src && /home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/external/cmake-3.22.1-linux-x86_64/bin/cmake -P CMakeFiles/pqxx.dir/cmake_clean_target.cmake
cd /home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/sandbox/linux-sandbox/79/execroot/__main__/bazel-out/k8-fastbuild/bin/external/pqxx/pqxx.build_tmpdir/src && /home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/external/cmake-3.22.1-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/pqxx.dir/link.txt --verbose=1
/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/sandbox/linux-sandbox/79/execroot/__main__/external/gcc_toolchain_x86_64/bin/ar qc libpqxx-7.9.a -lpqxx -lpq CMakeFiles/pqxx.dir/array.cxx.o CMakeFiles/pqxx.dir/binarystring.cxx.o CMakeFiles/pqxx.dir/blob.cxx.o CMakeFiles/pqxx.dir/connection.cxx.o CMakeFiles/pqxx.dir/cursor.cxx.o CMakeFiles/pqxx.dir/encodings.cxx.o CMakeFiles/pqxx.dir/errorhandler.cxx.o CMakeFiles/pqxx.dir/except.cxx.o CMakeFiles/pqxx.dir/field.cxx.o CMakeFiles/pqxx.dir/largeobject.cxx.o CMakeFiles/pqxx.dir/notification.cxx.o CMakeFiles/pqxx.dir/params.cxx.o CMakeFiles/pqxx.dir/pipeline.cxx.o CMakeFiles/pqxx.dir/result.cxx.o CMakeFiles/pqxx.dir/robusttransaction.cxx.o CMakeFiles/pqxx.dir/row.cxx.o CMakeFiles/pqxx.dir/sql_cursor.cxx.o CMakeFiles/pqxx.dir/strconv.cxx.o CMakeFiles/pqxx.dir/stream_from.cxx.o CMakeFiles/pqxx.dir/stream_to.cxx.o CMakeFiles/pqxx.dir/subtransaction.cxx.o CMakeFiles/pqxx.dir/time.cxx.o CMakeFiles/pqxx.dir/transaction.cxx.o CMakeFiles/pqxx.dir/transaction_base.cxx.o CMakeFiles/pqxx.dir/util.cxx.o CMakeFiles/pqxx.dir/version.cxx.o CMakeFiles/pqxx.dir/wait.cxx.o
/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ar: libdeps specified more than once
make[3]: *** [src/CMakeFiles/pqxx.dir/build.make:514: src/libpqxx-7.9.a] Error 1
make[3]: Leaving directory '/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/sandbox/linux-sandbox/79/execroot/__main__/bazel-out/k8-fastbuild/bin/external/pqxx/pqxx.build_tmpdir'
make[2]: *** [CMakeFiles/Makefile2:134: src/CMakeFiles/pqxx.dir/all] Error 2
make[2]: Leaving directory '/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/sandbox/linux-sandbox/79/execroot/__main__/bazel-out/k8-fastbuild/bin/external/pqxx/pqxx.build_tmpdir'
make[1]: *** [CMakeFiles/Makefile2:141: src/CMakeFiles/pqxx.dir/rule] Error 2
make[1]: Leaving directory '/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/sandbox/linux-sandbox/79/execroot/__main__/bazel-out/k8-fastbuild/bin/external/pqxx/pqxx.build_tmpdir'
make: *** [Makefile:189: pqxx] Error 2
If I remove "CMAKE_STATIC_LINKER_FLAGS": "-lpqxx -lpq",
from the file libpqxx.BUILD. It fails with (a lot of undefined reference to PQ
- the error below has been truncated):
INFO: Analyzed target //main:rinha (1 packages loaded, 355 targets configured).
ERROR: /home/manoelmenezes/projects/rinha-backend-2024-q1/main/BUILD:3:10: Linking main/rinha failed: (Exit 1): gcc failed: error executing CppLink command (from target //main:rinha)
(cd /home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/sandbox/linux-sandbox/81/execroot/__main__ && \
exec env - \
PATH=/home/manoelmenezes/.cache/bazelisk/downloads/sha256/1ca5d63a30244788ff9a5b7c35584f57111a68c82bbff2929ec7b2e99f35c7a8/bin:/home/manoelmenezes/bazelisk/bazelisk-linux-amd64:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games \
PWD=/proc/self/cwd \
external/gcc_toolchain_x86_64/bin/gcc -o bazel-out/k8-fastbuild/bin/main/rinha bazel-out/k8-fastbuild/bin/main/_objs/rinha/main.pic.o bazel-out/k8-fastbuild/bin/model/libclient-service.a bazel-out/k8-fastbuild/bin/external/served/libserved.a bazel-out/k8-fastbuild/bin/external/boost/libasio.a bazel-out/k8-fastbuild/bin/external/boost/libchrono.a bazel-out/k8-fastbuild/bin/external/boost/libsystem.a bazel-out/k8-fastbuild/bin/external/boost/libcontainer.a bazel-out/k8-fastbuild/bin/external/boost/libatomic.a bazel-out/k8-fastbuild/bin/external/boost/libatomic_sse.a bazel-out/k8-fastbuild/bin/external/boost/libregex.a bazel-out/k8-fastbuild/bin/external/boost/libexception.a bazel-out/k8-fastbuild/bin/external/pqxx/pqxx/lib/libpqxx.a -lpthread -Wl,-S -Wl,-z,relro,-z,now -pass-exit-codes -lm -lstdc++ --sysroot external/sysroot_x86_64/ -Bexternal/gcc_toolchain_x86_64/bin -Bexternal/sysroot_x86_64//usr/lib -Bexternal/sysroot_x86_64//lib64 -Lexternal/sysroot_x86_64//lib64 -Lexternal/sysroot_x86_64//usr/lib -Lexternal/sysroot_x86_64//lib/gcc/x86_64-linux/10.3.0)
# Configuration: 0e913ec885832ba80eb84357b2922ef6ed6bd55134ad82350d1f632bf75f4fa4
# Execution platform: @@local_config_platform//:host
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: bazel-out/k8-fastbuild/bin/external/pqxx/pqxx/lib/libpqxx.a(connection.cxx.o): in function `pqxx::connection::connection(pqxx::connection::connect_mode, pqxx::zview)':
connection.cxx:(.text+0x5e9): undefined reference to `PQconnectStart'
/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: connection.cxx:(.text+0x63f): undefined reference to `PQstatus'
/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: bazel-out/k8-fastbuild/bin/external/pqxx/pqxx/lib/libpqxx.a(connection.cxx.o): in function `pqxx::connection::poll_connect()':
connection.cxx:(.text+0x693): undefined reference to `PQconnectPoll'
/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: connection.cxx:(.text+0x6bc): undefined reference to `PQstatus'
/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: bazel-out/k8-fastbuild/bin/external/pqxx/pqxx/lib/libpqxx.a(connection.cxx.o): in function `pqxx::connection::sock() const &':
connection.cxx:(.text+0x7cd): undefined reference to `PQsocket'
...
/home/manoelmenezes/.cache/bazel/_bazel_manoelmenezes/67983900e4065458c8253806ac6d53ac/external/gcc_toolchain_x86_64_files/bin/x86_64-linux-ld: bazel-out/k8-fastbuild/bin/external/pqxx/pqxx/lib/libpqxx.a(util.cxx.o): in function `pqxx::describe_thread_safety()':
util.cxx:(.text.unlikely+0x330): undefined reference to `PQisthreadsafe'
collect2: error: ld returned 1 exit status
Upvotes: 0
Views: 222