【问题标题】:Cannot compile file using catch2 CATCH_CONFIG_MAIN无法使用 catch2 CATCH_CONFIG_MAIN 编译文件
【发布时间】:2021-05-16 11:05:04
【问题描述】:

我已经开始学习如何使用 Catch2 来测试我的 C++ 代码,并且正在尝试设置一个简单的测试。

我的文件夹结构包含三个文件都在同一个文件夹中:

catch.cpp //this is the catch_amalgamated.cpp file from GitHub
catch.hpp //this is the catch_amalgamated.hpp file from GitHub
test.cpp  //this is my test file

我在test.cpp 中写的都是:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

当我尝试编译 test.cpp 时,我收到以下错误,我认为这表明没有找到 main() 函数(?):

C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status

当我添加一个名义上的 main() 函数时,文件编译成功,但据我了解,#define CATCH_CONFIG_MAIN 应该为您创建 main() 函数,所以显然有些东西不起作用。

任何人都可以对此有所了解吗?

【问题讨论】:

    标签: c++ unit-testing testing catch2


    【解决方案1】:

    发生错误是因为 google 带您进入的默认分支是 catch2 的开发分支,所以我使用的是版本 3 文件并遵循版本 2 文档(因为它尚未更新)。一旦我下载了 v.2 文件,一切都开始正常工作了。

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 2012-10-02
      • 1970-01-01
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-25
      • 2013-11-24
      相关资源
      最近更新 更多