GoogleTest rename class not working in Visual Studio 2012

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 (issued from SVN):

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

      

The onIncomingMessage function signature:

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

      

Visual Studio 2012 contains 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. On Linux, it works fine.

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

+3


source to share


2 answers


I solved the problem. In my test case, I added the following:

::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, fixing the problem and compiling.

0


source


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



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

+1


source







All Articles