Open adam-azarchs opened 2 years ago
Actually slight correction here: gcc
isn't implicitly linking -lm
, but it is using a builtin implementation for nextafter
so that it doesn't require -lm
. At least our build of clang
(which, granted, is customized for our needs) does not do that.
The problem is very likely rules_cc
using clang
instead of clang++
as the C++ compiler in its toolchain definition. AFAIK, clang
is the C compiler driver, not the C++ compiler driver.
clang
>> /usr/bin/clang++ -o bazel-out/freebsd-fastbuild/bin/dummy_test -Xlinker -rpath -Xlinker '$ORIGIN/_solib_freebsd/' -Xlinker -rpath -Xlinker '$ORIGIN/dummy_test.runfiles/_main/_solib_freebsd/' -Lbazel-out/freebsd-fastbuild/bin/_solib_freebsd bazel-out/freebsd-fastbuild/bin/_objs/dummy_test/dummy_test.pic.o -lexternal_Sgoogletest~1.11.0_Slibgtest_Umain -lexternal_Sgoogletest~1.11.0_Slibgtest -pthread -Wl,-S -lstdc++ -Wl,-z,relro,-z,now -no-canonical-prefixes
clang++
>> /usr/bin/clang -o bazel-out/freebsd-fastbuild/bin/dummy_test -Xlinker -rpath -Xlinker '$ORIGIN/_solib_freebsd/' -Xlinker -rpath -Xlinker '$ORIGIN/dummy_test.runfiles/_main/_solib_freebsd/' -Lbazel-out/freebsd-fastbuild/bin/_solib_freebsd bazel-out/freebsd-fastbuild/bin/_objs/dummy_test/dummy_test.pic.o -lexternal_Sgoogletest~1.11.0_Slibgtest_Umain -lexternal_Sgoogletest~1.11.0_Slibgtest -pthread -Wl,-S -lstdc++ -Wl,-z,relro,-z,now -no-canonical-prefixes
ld: error: bazel-out/freebsd-fastbuild/bin/_solib_freebsd/libexternal_Sgoogletest~1.11.0_Slibgtest.so: undefined reference to nextafter [--no-allow-shlib-undefined]
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When compiling tests with bazel with clang on linux, I get a linker error
undefined reference to nextafter
.Does the bug persist in the most recent commit?
Yes.
What operating system and version are you using?
Linux. The specifics don't matter because we're using a custom sysroot, described below.
What compiler and version are you using?
clag
version 13.0.0 with--sysroot
pointing to a sysroot built usingcrosstool-ng
based on centos7.What build system are you using?
bazel version 5.1.1.
Additional context
This is basically the same bug as #3601, but the fix for that one made the incorrect assumption that this was only a problem on BSD. The correct solution is to change https://github.com/google/googletest/blob/0e402173c97aea7a00749e825b194bfede4f2e45/BUILD.bazel#L123-L125 to be simply
It won't do any harm when using compilers like gcc which add
-lm
implicitly, but it will prevent breakage for compilers which do not do this.