I've added Catch2
as a submodule to my project and included the Catch2/include/catch.hpp
header using the following code:
testmain.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);
}
but I get a linker error:
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
What am I doing wrong? I thought Catch2 was supposed to be self-contained in its header and didn't need any .cpp
file to provide its symbols?
Figured it out thanks to a response to one of the Catch2 Github Issues :
horenmar:
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.
The version in includes/
is the original file the "real" Catch2 header is generated from. The one you're supposed to include is in Catch2/single_include/catch2/catch.hpp
. So make sure your header search paths are set to search there for catch.hpp
, not in includes
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.