【发布时间】:2017-06-21 13:22:15
【问题描述】:
我正在迁移一些项目以使用 CMake 构建系统。现在我正在使用Catch 库添加带有一些单元测试的项目。它是仅标头库。旧的 Visual Studio 项目构建良好,但新的 CMake 项目提供未解决的外部符号链接器错误。我在我的一个源文件中定义了 CATCH_CONFIG_MAIN。添加了来自其他项目的测试所需的所有 cpp 文件,并且链接了其他测试项目所依赖的所有库。尽管如此,我只有从CMake 项目生成的未解决的外部符号错误:
ChipCountTests.obj : error LNK2019: unresolved external symbol "public: __thiscall Catch::SourceLineInfo::SourceLineInfo(char const *,unsigned int)" (??0SourceLineInfo@Catch@@QAE@PBDI@Z) referenced in function "void __cdecl `anonymous namespace'::`dynamic initializer for 'autoRegistrar1''(void)" (??__EautoRegistrar1@?A0xb4291ec5@@YAXXZ)
1>FlyingChipRewardCalculatorUT.obj : error LNK2001: unresolved external symbol "public: __thiscall Catch::SourceLineInfo::SourceLineInfo(char const *,unsigned int)" (??0SourceLineInfo@Catch@@QAE@PBDI@Z)
显然我缺少将一些配置从 vcxproj 添加到 CMakeLists.txt 但我目前无法弄清楚。
【问题讨论】:
-
您显然缺少一些 Catch 库。如果在 VS 项目的链接器部分找不到它们;然后尝试在 Catch 的标头中查找
#pragma comment( lib, "name-of-catch-library" ),这将导致链接器自动拾取命名库。 -
@Richard Critten 正如我所说,catch 库只是标头,没有 libs 。
-
您是否使用“官方”指令进行 CMake 集成? github.com/philsquared/Catch/blob/master/docs/build-systems.md(参见 CMake 部分)
-
能否请您提供一个minimal reproducible example 包括一些
CMakeLists.txt代码?
标签: c++ unit-testing build cmake catch-unit-test