c++ - Catch2 链接器错误
问题描述
我已将Catch2
作为子模块添加到我的项目中,并Catch2/include/catch.hpp
使用以下代码包含标题:
测试main.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
文件来提供其符号?
解决方案
霍伦马尔:
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
.
推荐阅读
- sql - 创建一个新列,其中包含来自另一列的子字符串列表
- python-3.x - 如何处理差异音频文件的 MFCC 功能差异
- json - Spring Boot 2 处理表单数据,其中 json 是键的值
- amazon-web-services - 如何对aws codepipeline更改集进行排队
- html - HTML default namespace vs. explicit namespace
- javascript - Javascript 扩展运算符可以包含对象的未定义字段吗?
- uwp - UWP 多视图:关闭主视图时关闭所有辅助视图
- jquery - 取消单身日期
- codenameone - 在代号中从一个点到另一个点画直线
- json - 使用动态密钥解组 json