3

I have the following enum class:

enum class Message : qint8 {INFO = 0, WARNING = 1, NON_FATAL_ERROR = 2, FATAL_ERROR = 3, DEBUG_INFO = 4};

and when I run the following code with Google Test (checked out from SVN):

EXPECT_NO_THROW(
     for(qint32 i = 0; i < 10; ++i)
         logger->onIncomingMessage(mapper::Message::INFO, "Testing logging system")
);

The signature of the onIncomingMessage function is:

 void onIncomingMessage(const mapper::Message &type, const QString &report);

Visual Studio 2012 shows the following exceptions:

Error   1   error LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > testing::FLAGS_gtest_death_test_style" (?FLAGS_gtest_death_test_style@testing@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) C:\Users\Michele\Projects\occupancymapper\build\Modules\Core\test_logger.obj
    3   IntelliSense: enum "mapper::Message" has no member "INFO"   c:\Users\Michele\Projects\occupancymapper\Modules\Core\test\test_logger.cpp 21
    4   IntelliSense: enum "mapper::Message" has no member "NON_FATAL_ERROR"    c:\Users\Michele\Projects\occupancymapper\Modules\Core\test\test_logger.cpp 30
    5   IntelliSense: enum "mapper::Message" has no member "DEBUG_INFO" c:\Users\Michele\Projects\occupancymapper\Modules\Core\test\test_logger.cpp 40
    6   IntelliSense: enum "mapper::Message" has no member "FATAL_ERROR"    c:\Users\Michele\Projects\occupancymapper\Modules\Core\test\test_logger.cpp 50
Error   2   error LNK1120: 1 unresolved externals   C:\Users\Michele\Projects\occupancymapper\build\Modules\Core\Debug\logger.exe   1

Without GoogleTests, the code in my class works fine, but when using GoogleTest, it doesn't. Under Linux, it works perfectly.

I've already applied the VARIADIC_MAX value (set to 10), as suggested here in a similar stackoverflow question, but it doesn't work. What I'm doing wrong?

3
  • Did you use _VARIADIC_MAX? You wrote VARIADIC_MAX (no underscore). Just to make sure you tried it already
    – Marco A.
    Oct 17, 2014 at 9:01
  • yes I tried with both, no chance. But this error is not related to Variadic number (i guess)
    – madduci
    Oct 17, 2014 at 9:48
  • Did you try to play with the GTEST_HAS_DEATH_TEST define when compiling GTest?
    – Lectem
    Oct 20, 2014 at 6:32

2 Answers 2

1

It looks the error has nothing to do with enum class - these are "IntelliSense" (editor code assistance) errors, not compiler's.

The real problem is that linker cannot find "testing::FLAGS_gtest_death_test_style" symbol. Have you specified .lib file to link with? Make you have built the google test library with the same code generation and debug level settings (this discussion may be helpful).

2
  • Thanks, I will try it and let you know
    – madduci
    Oct 18, 2014 at 8:55
  • So I've tried to compile gtest in the same way my application is built. The weird part is that only one test-case (the one calling the function above) is not compiling/is throwing errors, but the other ones aren't. Only the test-case which is using EXPECT_NO_THROW doesn't link. I'm using CMake and gtest as subproject to be compiled.
    – madduci
    Oct 20, 2014 at 7:16
0

I've solved the issue. In my test-case, I've added this:

::testing::FLAGS_gtest_death_test_style = "threadsafe";

right after

::testing::InitGoogleTest(&argc, argv);

because under Linux it was giving me problems.

Removing this line under MSVC, solved the issue and then it compiles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.