我已经看到很多具有相同问题的示例,但它们不适用于我的情况。
我有以下文件结构:
unit-tests/CMakeLists.txt
unit-tests/FlaAlgoTests/CMakeLists.txt
unit-tests/FlaAlgoTests/catch_test_runner.cpp
在Proj/CMakeLists.txt
:
ExternalProject_Add(
catch
PREFIX ${CMAKE_BINARY_DIR}/catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
TIMEOUT 10
UPDATE_COMMAND ${GIT_EXECUTABLE} pull
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
)
ExternalProject_Get_Property(catch source_dir)
include_directories(${source_dir}/single_include/catch2)
并在Proj/TestDir1/CMakeLists.txt
:
add_executable(
catch_test_runner
catch_test_runner.cpp
)
在哪里catch_test_runner.cpp
:
#include <iostream>
#include "catch.hpp"
#define CATCH_CONFIG_MAIN
TEST_CASE("Yeet", "[beep]"){
REQUIRE(true);
REQUIRE(2 == 1);
}
所有这些看起来都很好,似乎基本上是我为此找到的众多指南的复制/粘贴。但是,我收到以下问题:
[100%] Linking CXX executable catch_test_runner.exe
CMakeFiles/catch_test_runner.dir/catch_test_runner.o: In function `::____C_A_T_C_H____T_E_S_T__(void)':
/cygdrive/c/Users/dbak/Projects/firmware/unit-tests/FlaAlgoTests/catch_test_runner.cpp:7: undefined reference to `Catch::StringRef::StringRef(char const*)'
/cygdrive/c/Users/dbak/Projects/firmware/unit-tests/FlaAlgoTests/catch_test_runner.cpp:7:(.text+0x32): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Catch::StringRef::StringRef(char const*)'
/cygdrive/c/Users/dbak/Projects/firmware/unit-tests/FlaAlgoTests/catch_test_runner.cpp:7: undefined reference to `Catch::AssertionHandler::AssertionHandler(Catch::StringRef const&, Catch::SourceLineInfo const&, Catch::StringRef, Catch::ResultDisposition::Flags)'
所以,显然它能够链接到 catch.hpp,否则它就无法找到任何这些东西。很明显,我正在使用 catch 的 single_include 版本,这是我发现的所有关于同一问题的示例的问题。
我做错了什么?