Google Test: error LNK2019: unresolved external symbol with Visual Studio 2013

前端 未结 4 2295
忘了有多久
忘了有多久 2021-02-14 10:53

I\'m trying to get my first ever unit test with Google Test framework + Visual Studio 2013.However I\'m hitting the below error and can\'t understand why.

相关标签:
4条回答
  • 2021-02-14 11:09

    The issue here is that you didn't include MyMultiplier.h/cpp in the actual test project.

    Add it to the project file (right-click, add existing item and navigate to the files).

    0 讨论(0)
  • 2021-02-14 11:11

    Adding dependencies for .lib files is a manual step in Visual Studio.

    1. Open the Property Pages box for your project by right clicking on your project in the solution explorer (in your case, MyMultiplier_UnitLevelTest)
    2. Click on the Linker folder
    3. Open the Input page
    4. Add any necessary .libs in the Additional Dependencies field

    More information can be found here: http://msdn.microsoft.com/en-CA/library/ba1z7822.aspx

    0 讨论(0)
  • 2021-02-14 11:13

    I had the same problem, and the easiest solution when you want a standalone google test is to link gtest_main as well as gtest. You can set your Visual Studio project as Executable and then link with gtest_main and gtest.

    0 讨论(0)
  • 2021-02-14 11:21

    The root cause is the project type is not set correctly.

    In this example, there are three projects:

    1. FirstGoogleTest, which is the testee. the class to be tested resides in here.
    2. googleTest, which is the google test framework
    3. MyMultiplier_UnitLevelTest, which is the ULT project that contains the tests.

    The root cause is "FirstGoogleTest" project's configuration Type was set to .exe, which is the same as the ULT project. so the ult test cannot get the externals from "FirstGoogleTest". After changing "FirstGoogleTest" configuration Type to Static library (.lib). the solution can be compiled correctly and the ULT runs fine.

    0 讨论(0)
提交回复
热议问题