Search code examples
googletest

error LNK1104 cannot open file 'gtest.lib'


I was trying to install a neural networks toolbox called CarlSim using visual studio 2012, in which they use gtest in their code. I try to install gtest by downloading it online and build using gtest.sln file. It gives me two warnings. I guess these two warnings are the reason for this error. But I don't know how to solve this. The gtest seems only can build gtestd.lib. Below is the error during install of the neural network toolbox

Error   2   error LNK1104: cannot open file 'gtest.lib' C:\Users\Dukerama\Desktop\CarlSim\carlsim\test\LINK carlsim_tests

Below are the warnings of the gest.

    1>------ Rebuild All started: Project: gtest, Configuration: Debug Win32 ------
1>  gtest-all.cc
1>C:\Program Files(x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(1299,5):      warning MSB8012: TargetPath(C:\Users\Dukerama\Desktop\gtest\gtest-  1.6.0\msvc\gtest/Debug\gtest.lib) does not match the Library's OutputFile property value (C:\Users\Dukerama\Desktop\gtest\gtest-1.6.0\msvc\gtest\Debug\gtestd.lib). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile).
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(1301,5): warning MSB8012: TargetName(gtest) does not match the Library's OutputFile property value (gtestd). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Lib.OutputFile).
1>  gtest.vcxproj -> C:\Users\Dukerama\Desktop\gtest\gtest-1.6.0\msvc\gtest/Debug\gtest.lib
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Solution

  • Output from build command in VS you have posted suggests that there are inconsistencies between certain values in VS project properties for gtest (located in 'Configuration Properties -> General' and in 'Configuration Properties -> Librarian -> General'). However, output also suggests that the gtest library is built at location:

    C:\Users\Dukerama\Desktop\gtest\gtest-1.6.0\msvc\gtest/Debug\gtest.lib

    You should take this file and place it in directory where CarlSim toolbox expects to find the gtest library. You can find this out in the VS project properties for CarlSim ('Configuration Properties -> Linker -> General -> AdditionalLibraryDirectories').

    P.S. Make sure that both gtest and CarlSim link to the same runtime library, or you'll get more linker errors. You can inspect the runtime library in their VS project properties at 'Configuration Properties -> C/C++ -> Code Generation -> Runtime Library'.