Build issue with clang on MSYS

Open
#2,937 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cmake, cpp

Research direction

Start by reproducing the Clang 18 build using the minimal test in tests/objects/gain.cpp. Inspect the generated CMake link command and Catch2 targets, especially the Catch2Main and Catch2 libraries shown in the failure. Done means the test_gain executable links and builds successfully with Clang as it does with GCC.

Written by the indexing model from the issue text.

Description

Describe the bug
When building on ubuntu with clang-18:

ld.lld: error: undefined symbol: Catch::ReusableStringStream::str() const

ld.lld: error: undefined symbol: 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&)

ld.lld: error: undefined symbol: Catch::StringMaker<double, void>::convert(double)

CI failure: https://github.com/celtera/avendish/actions/runs/11863814439/job/33065997014?pr=42
Here are my complete build flags - I can see that Catch2 is correctly linked:

[ 97%] Building CXX object CMakeFiles/test_gain.dir/tests/objects/gain.cpp.o
/usr/bin/clang++-18 -DDEVELOPMENT -DFMT_HEADER_ONLY=1 -I/home/runner/work/avendish/avendish/build-debug -I/home/runner/work/avendish/avendish -I/home/runner/work/avendish/avendish/build-debug/_deps/qlibs_reflect-src -I/home/runner/work/avendish/avendish/score/3rdparty/vst3 -I/home/runner/work/avendish/avendish/include -I/home/runner/work/avendish/avendish/build-debug/_deps/fmt-src/include -I/home/runner/work/avendish/avendish/build-debug/_deps/magic_enum-src/include -I/home/runner/work/avendish/avendish/build-debug/_deps/catch2-src/src/catch2/.. -I/home/runner/work/avendish/avendish/build-debug/_deps/catch2-build/generated-includes -isystem /opt/ossia-sdk/boost/include -Wno-non-virtual-dtor -g -std=gnu++23 -fPIE -fvisibility=internal -fvisibility-inlines-hidden -fno-semantic-interposition -fPIC -stdlib=libc++ -fno-stack-protector -fno-ident -fno-plt -ffunction-sections -fdata-sections -MD -MT CMakeFiles/test_gain.dir/tests/objects/gain.cpp.o -MF CMakeFiles/test_gain.dir/tests/objects/gain.cpp.o.d -o CMakeFiles/test_gain.dir/tests/objects/gain.cpp.o -c /home/runner/work/avendish/avendish/tests/objects/gain.cpp
[ 97%] Linking CXX executable test_gain
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/test_gain.dir/link.txt --verbose=1
ld.lld: error: undefined symbol: Catch::ReusableStringStream::str() const
>>> referenced by gain.cpp:7 (/home/runner/work/avendish/avendish/tests/objects/gain.cpp:7)
>>>               CMakeFiles/test_gain.dir/tests/objects/gain.cpp.o:(CATCH2_INTERNAL_TEST_0())
>>> referenced by gain.cpp:11 (/home/runner/work/avendish/avendish/tests/objects/gain.cpp:11)
>>>               CMakeFiles/test_gain.dir/tests/objects/gain.cpp.o:(CATCH2_INTERNAL_TEST_0())

ld.lld: error: undefined symbol: 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&)
>>> referenced by catch_decomposer.hpp:79 (_deps/catch2-src/src/catch2/../catch2/internal/catch_decomposer.hpp:79)
>>>               CMakeFiles/test_gain.dir/tests/objects/gain.cpp.o:(Catch::BinaryExpr<double, double>::streamReconstructedExpression(std::__1::basic_ostream<char, std::__1::char_traits<char>>&) const)

ld.lld: error: undefined symbol: Catch::StringMaker<double, void>::convert(double)
>>> referenced by catch_tostring.hpp:150 (_deps/catch2-src/src/catch2/../catch2/catch_tostring.hpp:150)
>>>               CMakeFiles/test_gain.dir/tests/objects/gain.cpp.o:(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> Catch::Detail::stringify<double>(double const&))
clang++-18: error: linker command failed with exit code 1 (use -v to see invocation)
/usr/bin/clang++-18  -Wno-non-virtual-dtor -g -fuse-ld=lld -Xlinker --dependency-file -Xlinker CMakeFiles/test_gain.dir/link.d CMakeFiles/test_gain.dir/tests/objects/gain.cpp.o -o test_gain  _deps/fmt-build/libfmtd.a -Wl,--gc-sections -lc++ -Bsymbolic _deps/catch2-build/src/libCatch2Maind.a _deps/catch2-build/src/libCatch2d.a
gmake[2]: *** [CMakeFiles/test_gain.dir/build.make:104: test_gain] Error 1

And the very minimal test file causing the failure: https://github.com/celtera/avendish/blob/feature/catch2/tests/objects/gain.cpp

It works fine with gcc on the same platform.

Expected behavior
Build succeeds

Platform information:

  • OS: Ubuntu 24.04 as provided by GH actions
  • Compiler+version: Clang 18 as provided by apt.llvm.org
  • Catch version: current HEAD
Dominant language
C++
Stars
21.6k
Forks
3.4k
Avg merge
3d 12h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from catchorg/Catch2

All issues in catchorg/Catch2

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.