benchmark icon indicating copy to clipboard operation
benchmark copied to clipboard

[BUG] undefined references to lround, log, pow: benchmark uses math.h/cmath but doesn't specify the `-lm` linker flag on FreeBSD/OpenBSD when using Bazel

Open yesudeep opened this issue 3 years ago • 3 comments

Describe the bug

❯ bazel build //test/...
WARNING: /usr/home/yesudeep/.cache/bazel/_bazel_yesudeep/ffbd632d168ee0cddab7ac9029ce644e/external/remote_java_tools_linux/BUILD:671:11: in hdrs attribute of cc_library rule @remote_java_tools_linux//:combiners: Artifact 'external/remote_java_tools_linux/java_tools/src/tools/singlejar/zip_headers.h' is duplicated (through '@remote_java_tools_linux//:transient_bytes' and '@remote_java_tools_linux//:zip_headers'). Since this rule was created by the macro 'cc_library', the error might have been caused by the macro implementation
INFO: Analyzed 30 targets (0 packages loaded, 0 targets configured).
INFO: Found 30 targets...
ERROR: /usr/home/yesudeep/code/yesudeep/benchmark/test/BUILD:40:12: Linking of rule '//test:args_product_test' failed (Exit 1) clang failed: error executing command /usr/bin/clang -o bazel-out/freebsd-fastbuild/bin/test/args_product_test '-Wl,-rpath,$ORIGIN/../_solib_freebsd/' -Lbazel-out/freebsd-fastbuild/bin/_solib_freebsd ... (remaining 10 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
ld: error: bazel-out/freebsd-fastbuild/bin/_solib_freebsd/liblibbenchmark.so: undefined reference to lround
ld: error: bazel-out/freebsd-fastbuild/bin/_solib_freebsd/liblibbenchmark.so: undefined reference to log
ld: error: bazel-out/freebsd-fastbuild/bin/_solib_freebsd/liblibbenchmark.so: undefined reference to pow
clang: error: linker command failed with exit code 1 (use -v to see invocation)
INFO: Elapsed time: 0.437s, Critical Path: 0.25s
INFO: 1 process: 1 processwrapper-sandbox.
FAILED: Build did NOT complete successfully

System Which OS, compiler, and compiler version are you using:

  • OS: FreeBSD 12.1-STABLE (GhostBSD 20.08.20 XFCE)
  • Compiler and version: clang version 12.0.0

To reproduce Steps to reproduce the behavior:

  1. git clone https://github.com/google/benchmark
  2. bazel build //test/...

Expected behavior Expected to build and run benchmarks without linker errors.

yesudeep avatar Aug 27 '20 02:08 yesudeep

Fixed by 4475ff6b8a7a4077d7492b76ef5278a3dc53a2e4

yesudeep avatar Aug 28 '20 08:08 yesudeep

Turns out that https://github.com/google/benchmark/commit/4475ff6b8a7a4077d7492b76ef5278a3dc53a2e4 isn't the correct fix for this problem. Bazel apparently uses /usr/bin/clang to link C++ code, when it should be using /usr/bin/clang++. Sending a PR to revert this change.

yesudeep avatar Aug 30 '20 05:08 yesudeep

Here's a reference to the actual problem: https://github.com/bazelbuild/bazel/issues/12023

yesudeep avatar Aug 30 '20 05:08 yesudeep