catchorg / catchorg/Catch2

Catch2 fails to link when using a CMake multi-config generator

Open
#2,892 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

**Describe the bug**
When Catch2 is installed using Conan into a project using CMake, and the project uses a multi-config generator such as "Ninja Multi-Config", building the project results in linker errors having to do with missing references to Catch2 symbols.

**Expected behavior**
Project should link successfully.

**Reproduction steps**
1. Install Catch2 using Conan:
```
[test_requires]
catch2/3.6.0
```
2. Use Conan's CMake integration to find and link against Catch2:
```
add_executable(xxx_test ${SOURCES_WITHOUT_MAIN} ${TEST_SOURCES})
find_package(Catch2 REQUIRED)
target_link_libraries(xxx_test PRIVATE Catch2::Catch2WithMain)
```
3. Configure + build using CMake and the "Ninja Multi-Config" generator
```
cmake -G "Ninja Multi-Config" -S. -B ./build --preset=conan-release && cmake --build ./build
```
4. Observe link errors:
```
FAILED: Debug/xxx_test
...
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
/usr/bin/ld: CMakeFiles/xxx_test.dir/Debug/test/XXX.test.cpp.o: in function `CATCH2_INTERNAL_TEST_0()':
/home/tom/projects/xxx/projects/xxx/test/XXX.test.cpp:6:(.text+0x4e): undefined reference to `Catch::ReusableStringStream::ReusableStringStream()'
...
```

**Platform information:**

- OS: **Arch Linux**
- Compiler+version: **GCC v14.1.1**
- Catch version: **v3.6.0**
- Conan version: **2.5.0**

**Additional context**
1. When changing the generator to "Ninja" things work as expected.
2. The following comment exists in `Catch2-Target-release.cmake`:
```
# FIXME: What is the result of this for multi-config? All configs adding themselves to path?
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.