Catch2
Catch2 copied to clipboard
v3: multiple linker errors when using libcxx
Describe the bug When trying to compile any Catch2 v3 test case with libcxx as stdlib, multiple linker errors pop up.
Expected behavior I expected to be able to use libcxx as a drop-in replacement for libstdc++.
Reproduction steps Consider this testcase:
#include <catch2/catch_test_macros.hpp>
TEST_CASE() {
REQUIRE(0 == 0);
}
Compile it with clang++, using libcxx as stdlib:
clang++ -stdlib=libc++ -lCatch2 -lCatch2Main test.cpp
Get following errors:
/usr/bin/x86_64-pc-linux-gnu-ld.bfd: test-e75290.o: in function `Catch::BinaryExpr<int, int>::streamReconstructedExpression(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const':
test.cpp:(.text._ZNK5Catch10BinaryExprIiiE29streamReconstructedExpressionERNSt3__113basic_ostreamIcNS2_11char_traitsIcEEEE[_ZNK5Catch10BinaryExprIiiE29streamReconstructedExpressionERNSt3__113basic_ostreamIcNS2_11char_traitsIcEEEE]+0x70): undefined reference to `Catch::formatReconstructedExpression(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Catch::StringRef, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)'
/usr/bin/x86_64-pc-linux-gnu-ld.bfd: /tmp/test-e75290.o: in function `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::Detail::stringify<int>(int const&)':
test.cpp:(.text._ZN5Catch6Detail9stringifyIiEENSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEERKT_[_ZN5Catch6Detail9stringifyIiEENSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEERKT_]+0x1e): undefined reference to `Catch::StringMaker<int, void>::convert(int)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Platform information:
$ clang++ -v
clang version 17.0.5
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/17/bin
Configuration file: /etc/clang/x86_64-pc-linux-gnu-clang++.cfg
libcxx version 17.0.5, Catch2 version 3.4.0 (Gentoo enables -DCATCH_DEVELOPMENT_BUILD=ON if that could be important).
Could be related to #2728
Catch2Main depends on Catch2. IIRC for bfd link order matters, so try that first.
Same errors are produced even if I don't link to Catch2Main, so I assume it's not relevant.
The problem is the Catch2 must also be built with libc++. So you likely need to build it from source.
The problem is the
Catch2must also be built withlibc++. So you likely need to build it from source.
This is what I think may be happening as well.
Hmm, is it possible to fix this?
Anyway, I think it should be mentioned somewhere in the documentation that Catch relies somewhat heavily on the standard library ABI. I couldn't find this mention anywhere, but I could've missed it though.
Hmm, is it possible to fix this?
Sure it is. Compile Catch2 with libc++ and I expect it'd work.
I think it should be mentioned somewhere in the documentation that Catch relies somewhat heavily on the standard library ABI.
Pretty much all C++ libraries are susceptible to this. It's just one of those things you have to deal with when trying to use a non-default standard library for your given OS. I think it's outside the scope of Catch2's documentation to cover this.