首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Catch2链接器错误

Catch2链接器错误
EN

Stack Overflow用户
提问于 2021-04-23 20:13:30
回答 1查看 750关注 0票数 1

我将Catch2作为子模块添加到我的项目中,并使用以下代码包括了Catch2/include/catch.hpp头:

testmain.cpp:

代码语言:javascript
复制
#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);
}

但是我看到一个链接错误:

代码语言:javascript
复制
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文件来提供它的符号?

EN

回答 1

Stack Overflow用户

发布于 2021-04-23 20:13:30

多亏了一个对Catch2 Github问题之一的响应

horenmar:

代码语言:javascript
复制
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中搜索。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67236321

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档