c++ - 无法让谷歌测试工作

标签 c++ visual-studio-2012 googletest

#include "gtest/gtest.h"

TEST(BattleUnitTest, CountryReturnsProperName) {
    EXPECT_EQ(1, 1);
}

int main(int argc, char* argv[]) {
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

我似乎无法让谷歌测试工作。我运行 Nuget 包管理器来获取 gtest。它一直给我这些错误:

Severity    Code    Description Project File    Line
Error   LNK2019 unresolved external symbol "bool __cdecl testing::internal::IsTrue(bool)" (?IsTrue@internal@testing@@YA_N_N@Z) referenced in function "public: void __thiscall testing::internal::scoped_ptr<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::reset(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *)" (?reset@?$scoped_ptr@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@internal@testing@@QAEXPAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) Assignment1_Battle  E:\C++\Projects\Assignment1_Battle\Assignment1_Battle\BattleUnitTest.obj    1

.

    Severity    Code    Description Project File    Line
Error   LNK2019 unresolved external symbol "public: __thiscall testing::Message::Message(void)" (??0Message@testing@@QAE@XZ) referenced in function "private: virtual void __thiscall BattleUnitTest_CountryReturnsProperName_Test::TestBody(void)" (?TestBody@BattleUnitTest_CountryReturnsProperName_Test@@EAEXXZ)    Assignment1_Battle  E:\C++\Projects\Assignment1_Battle\Assignment1_Battle\BattleUnitTest.obj    1

.

Severity    Code    Description Project File    Line
Error   LNK2019 unresolved external symbol "class testing::AssertionResult __cdecl testing::internal::EqFailure(char const *,char const *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?EqFailure@internal@testing@@YA?AVAssertionResult@2@PBD0ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1_N@Z) referenced in function "class testing::AssertionResult __cdecl testing::internal::CmpHelperEQ<int,int>(char const *,char const *,int const &,int const &)" (??$CmpHelperEQ@HH@internal@testing@@YA?AVAssertionResult@1@PBD0ABH1@Z) Assignment1_Battle  E:\C++\Projects\Assignment1_Battle\Assignment1_Battle\BattleUnitTest.obj    1

我可以发布所有错误,但几乎所有错误都与 LNK2019 有关。有谁知道如何解决这些错误?

最佳答案

我遇到了这个问题,但我的链接器设置没有任何问题。我最终找到了这篇文章 PrintTo link issue :

This was indeed caused by the mismatching /Zc:wchar_t setting. I failed to mention in the previous post that I had made that example code as Qt Console Application project (with Qt Add-in 1.1.9). Apparently the wchar_t setting is set to 'no' with that project template, while Google Mock's project setting is set to 'yes' by default. When I recompiled Google Mock with the setting set to 'no' the linker problem went away.

当我将设置“Treat WChar_t As Built in Type”更改为“Yes/Zc:wchar_t”时,构建工作正常。

关于c++ - 无法让谷歌测试工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33358784/

相关文章:

c++ - 哪个编译器对于以下重载/特化行为是正确的?

c++ - 使用简单代码从已排序的链表中删除重复节点

C++堆栈实现,不在函数中保留内存

c++ - 在函数周围传递 C 风格的字符串

c++ - 如何使用 C++ 中的 gtest 测试具有不同构造函数的多个接口(interface)实现?

c++ - 使用 Visual Studio 2019 和 cmake 进行谷歌测试

text-editor - Visual Studio 2012 文本编辑器中的丑陋选择

c# - 如何格式化运算符 C++ Visual Studio 之间的空间?

c++ - 为什么 MinGW 的 std::to_string() 运行速度比 VS2012 慢 16 倍

c++ - 用谷歌测试重载函数