#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/