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?

Community
  • 1
  • 1
madduci
  • 2,635
  • 1
  • 32
  • 51

2 Answers2

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).

Community
  • 1
  • 1
dewaffled
  • 2,850
  • 2
  • 17
  • 30
  • Thanks, I will try it and let you know – madduci Oct 18 '14 at 08: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 '14 at 07: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.

madduci
  • 2,635
  • 1
  • 32
  • 51