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

天大地大妈咪最大 提交于 2019-12-05 22:06:52

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.

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).

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!