我有以下枚举类:

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

当我使用Google Test运行以下代码(从SVN中 check out )时:
EXPECT_NO_THROW(
     for(qint32 i = 0; i < 10; ++i)
         logger->onIncomingMessage(mapper::Message::INFO, "Testing logging system")
);

onIncomingMessage函数的签名为:
 void onIncomingMessage(const mapper::Message &type, const QString &report);

Visual Studio 2012显示以下异常:
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

没有GoogleTests,我类的代码就可以正常工作,但是当使用GoogleTest时,它不能。在Linux下,它可以完美运行。

我已经应用了VARIADIC_MAX值(设置为10),就像在类似的stackoverflow question中所建议的那样,但是它不起作用。
我做错了什么?

最佳答案

看起来该错误与枚举类无关-这些是“IntelliSense”(编辑器代码帮助)错误,而不是编译器错误。

真正的问题是链接器找不到“testing::FLAGS_gtest_death_test_style”符号。您是否指定了要链接的.lib文件?使您使用相同的代码生成和调试级别设置构建了google测试库(this的讨论可能会有所帮助)。

关于c++ - GoogleTest枚举类在Visual Studio 2012中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26355385/

10-13 08:23