我将Catch2作为子模块添加到我的项目中,并使用以下代码包括了Catch2/include/catch.hpp头:
testmain.cpp:
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
TEST_CASE( "Test test", "[test]" ) {
REQUIRE(true);
}但是我看到一个链接错误:
Undefined symbols for architecture x86_64: "Catch::NameAndTags::NameAndTags(Catch::StringRef const&, Catch::StringRef const&)", referenced from: ___cxx_global_var_init.1 in testmain.cpp.o我做错了什么?我认为Catch2应该是自包含在它的标题中,并且不需要任何.cpp文件来提供它的符号?
发布于 2021-04-23 20:13:30
horenmar:
You are supposed to use the single-include version.
It is possible to use the headers in include/, but then you have to also compile and
link the implementation files in there and you are not provided with any guarantees
vis-a-vis stability and functionality.includes/中的版本是生成“真实”Catch2头的原始文件。你应该包括在Catch2/single_include/catch2/catch.hpp里的那个。因此,确保头搜索路径设置为搜索catch.hpp,而不是在includes中搜索。
https://stackoverflow.com/questions/67236321
复制相似问题