one or more multiply defined symbols found when using catch2

Hi,

I am #including catch.hpp in several source files of a project but I get


one or more multiply defined symbols found


What can be going on? Maybe I need to #define something before #including catch.hpp?

Regards,
Juan Dent
Do you get more specific linker errors, perhaps earlier in the output? You should see some sort of name-mangled symbol it says is duplicated.

Can you create a minimal example that reproduces the error?
Last edited on
> one or more multiply defined symbols found
Two common mistakes
1. having #include "somefile.cpp" somewhere in the code, as a way to avoid having to add source files to your project / makefile.
2. having definitions (hence the error message - multiple definitions) in header files.

A definition would be something like
1
2
3
4
void foo ( ) {
  cout << "this is foo";
}
int bar = 42;


There are some exceptions:
- function definitions within the declaration of a class are OK in header files.
- function definitions which are part of a template are OK in header files.
- function definitions which have the inline specifier are OK in header files.
- function definitions which have the static specifier are OK in header files.

Catch2 is a header only library where only one of the source files must #define CATCH_CONFIG_MAIN which includes the definitions as @salem c suggested, but I was doing it at the level of the project - thus the definitions were repeated at each source file...
When I removed this #define from the project the multiple definitions were removed - all I needed was to add the #define to 1 source file before including the catch.hpp header file.
Problem solved. Thanks

Topic archived. No new replies allowed.