简体   繁体   English

无法使用 catch2 CATCH_CONFIG_MAIN 编译文件

[英]Cannot compile file using catch2 CATCH_CONFIG_MAIN

I've started out learning how to use Catch2 for testing my C++ code and am trying to set up a simple test.我已经开始学习如何使用 Catch2 来测试我的 C++ 代码,并且正在尝试设置一个简单的测试。

My folder structure consists of three files all in the same folder:我的文件夹结构由三个文件组成,它们都在同一个文件夹中:

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

All I have written in test.cpp is:我在test.cpp中写的只是:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

When I try to compile test.cpp I get the following error which I think indicates that there is no main() function found(?):当我尝试编译test.cpp时,我收到以下错误,我认为这表明没有main() function found(?):

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

When I add a nominal main() function, the file compiles successfully, but as I understand it #define CATCH_CONFIG_MAIN is supposed to create the main() function for you so something clearly isn't working.当我添加一个标称的main() function 时,该文件编译成功,但据我了解, #define CATCH_CONFIG_MAIN应该为您创建main() function,所以显然有些东西不起作用。

Can anyone shed any light on this?任何人都可以对此有所了解吗?

The error was occurring because the default branch that google takes you to is the development branch of catch2, so I was using version 3 files and following version 2 documentation (as it has not been updated yet).发生错误是因为 google 将您带到的默认分支是 catch2 的开发分支,所以我使用的是版本 3 文件并遵循版本 2 文档(因为它尚未更新)。 Once I downloaded the v.2 file everything started working fine.一旦我下载了 v.2 文件,一切都开始正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM