1

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?

uliwitness
  • 8,532
  • 36
  • 58

1 Answers1

1

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.

uliwitness
  • 8,532
  • 36
  • 58
  • 1
    I strongly recommend `-I Catch2/single_include` and using `#include `, as that is how they intend for you to consume the library (as opposed to `#include `). I can't remember which issue on the GitHub I saw that discussed this, but I do recall seeing it – Justin Apr 23 '21 at 20:17