【问题标题】:Unable to build the Test Project that used Google test无法构建使用 Google 测试的测试项目
【发布时间】:2013-05-06 00:42:09
【问题描述】:

我构建了 google 测试项目。

我在General -> Addition Include Directories.中添加了包含目录
我将库目录添加到Linker -> Additional Library directories
我将 gtest_maind.lib 和 gtestd.lib 添加到Linker -> Input -> Additional Dependencies

我按照另一个链中的说明更改了Code Generation -> Runtime Library to Multi-threaded Debug (/MTd)

注意:我使用的是 Visual Studio 2010

尽管做了上述所有操作,我仍然收到以下链接错误

Error   1   error LNK2019: unresolved external symbol "public: __thiscall 
Utility::~Utility(void)" (??1Utility@@QAE@XZ) referenced in function "private: virtual
void __thiscall UtiltyTest_test1_Test::TestBody(void)" (?
TestBody@UtiltyTest_test1_Test@@EAEXXZ) C:\Users\<username>\Documents\Visual Studio 
2010\Projects\Calc\CalTest\UtilityTest.obj

我在这里错过了什么吗?谁能帮我解决这个错误。

【问题讨论】:

    标签: c++ visual-studio-2010 linker-errors googletest


    【解决方案1】:

    您是否要测试任何 .c 文件? 因为如果你是你应该试试这个:

    #ifdef __cplusplus 
      extern "C" {
    #endif
        void cFunctionCalledFromCppFile();
    #ifdef __cplusplus 
      }
    #endif
    

    【讨论】:

    • 不,我只使用 .cpp 文件