我见过许多关于同样问题的例子,但它们不适用于我的情况。
我有以下文件结构:
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,否则它就找不到这些东西了。显然,我使用的是single_include版本的catch,这是我在同一问题上找到的所有示例的问题。
我做错什么了?
发布于 2019-05-18 08:09:24
行#define CATCH_CONFIG_MAIN告诉catch.hpp报头,它也应该发出Catch实现。但为此目的,这一行应该出现在之前,,包括catch.hpp
#define CATCH_CONFIG_MAIN // This should come **before** including the 'catch.hpp'.
#include "catch.hpp"https://stackoverflow.com/questions/56194930
复制相似问题