I get this error in a C++ file where I am writing some tests:
error: no member named 'Session' in namespace 'Catch'
testResult = Catch::Session().run(test_argc, test_argv);
~~~~~~~^
Looking at the catch.hpp single header file, I noticed that the code that should implement the Session() member function is greyed out, probably because of an #ifdef somewhere, which I cannot find.
Is there any macro to set to use the Session class?
Catch versions: 1.5.3 and 1.5.6.
Reference: https://github.com/philsquared/Catch/blob/master/docs/own-main.md
You're attempting to call the constructor of Catch::Session
from a file where you're not defining your own main
to execute. According to the documentation on defining your own main, there is supposed to be only one instance of Catch::Session
:
Catch::Session session; // There must be exactly once instance
It's likely Catch is preventing construction of Catch::Session
in translation units where it can't be used in a custom main
definition (since that's where it's supposed to be used), to prevent exactly the mistake you've made from compiling.
Reference to https://github.com/catchorg/Catch2/blob/master/docs/own-main.md
You can only provide main in the same file you defined CATCH_CONFIG_RUNNER.
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
int main( int argc, char* argv[] ) {
// global setup...
int result = Catch::Session().run( argc, argv );
// global clean-up...
return result;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With