我正在尝试为Catch2编写测试脚本,但遇到一些严重的抓头错误。
我一直在网上寻找与我相似的案例,但似乎他们也使用了CMakeList.txt文件,而我只从Catch2自述文件下载catch.hpp。
在我的文件夹中,我放置了getDifferences.cpp
,getDifferences.hpp
和test.cpp
#define CATCH_CONFIG_MAIN
,#include "catch.hpp"
,#include "getDifferences.hpp"
在其标题的顶部,并且未定义其他main()。
我的笔记本电脑: 作业系统:Dualboot ChromeOS / XFCE4 编译器+版本g ++(Ubuntu 5.4.0) 捕获版本:2.10.0最新版本
接下来,我尝试使用以下命令编译test.cpp
:
g++ -std=gnu++11 test.cpp
并导致以下错误:
/tmp/ccd1AxMb.o: In function `____C_A_T_C_H____T_E_S_T____0()':
test.cpp:(.text+0x27be4): undefined reference to `getDifferences(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
test.cpp:(.text+0x27daf): undefined reference to `getDifferences(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
test.cpp:(.text+0x27f71): undefined reference to `getDifferences(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/tmp/ccd1AxMb.o: In function `____C_A_T_C_H____T_E_S_T____2()':
test.cpp:(.text+0x284b7): undefined reference to `getDifferences(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
test.cpp:(.text+0x28740): undefined reference to `getDifferences(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/tmp/ccd1AxMb.o:test.cpp:(.text+0x28ca8): more undefined references to `getDifferences(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' follow
collect2: error: ld returned 1 exit status
我不确定为什么会收到对getDifferences的未定义引用,该函数已定义并包含在头文件中。任何指针都将非常有帮助。预先谢谢你!