The problem is specific to VS2010. I couldn't reproduce it in a simple case to give an MCVE (see below).
There is some old, legacy project. It has (among others) 3 C++ projects:
GoogleTestingFramework - a
.lib
project that delivers features fromGTest
andGMock
. Created for usage simplicity.OldLegacyProject - an old
.exe
project.- The entities on interest here are
Class1
andClass2
. Both are in separate files,Class1.cpp
+Class1.hpp
(the same for Class2).
- The entities on interest here are
OldLegacyProjectUnitTests - a new
.exe
project with Unit Tests written usingGTest
andGMock
.- This project is referencing
GoogleTestingFramework
andOldLegacyProject
using Project References. - In the reference properties, I follow the rules from
Visual Studio 2010 not autolinking static libraries from projects that are dependencies as it should be supposed to , especially this part:
- I tried to change
Use Library Dependency Inputs
totrue
, but it didn't change anything regarding the problem
- I tried to change
- classes from this project use
Class1
andClass2
directly (since they are unit tests for them) and need to be linked with their.obj
's
- This project is referencing
When I try to build everything, I get following liker errors:
3>OldLegacyProjectUnitTests.obj : error LNK2019: unresolved external symbol "public: __thiscall Class1::Class1(class Class2 &)" (??0Class1@@QAE@AAVClass2@@@Z) referenced in function "private: virtual void __thiscall SimpleCase_Should_CreateNewInstance_When_Called_Test::TestBody(void)" (?TestBody@SimpleCase_Should_CreateNewInstance_When_Called_Test@@EAEXXZ)
3>OldLegacyProjectUnitTests.obj : error LNK2019: unresolved external symbol "public: __thiscall Class2::Class2(void)" (??0Class2@@QAE@XZ) referenced in function "private: virtual void __thiscall SimpleCase_Should_CreateNewInstance_When_Called_Test::TestBody(void)" (?TestBody@SimpleCase_Should_CreateNewInstance_When_Called_Test@@EAEXXZ)
3>../Debug/OldLegacyProjectUnitTests.exe : fatal error LNK1120: 2 unresolved externals
I created a simple example using the guide: Google Test #1.b: Setup Googletest in Visual Studio, with the same configuration as above, and it works correctly.
The questions are:
- Why doesn't the linker see those classes despite the Project Reference?
- How to see what the linker actually "sees"? (at least, which files)
- Consequently: how to feed the classes to the linker?
If I explicitly add a path to those .obj
's, everything compiles and links correctly. But, this is a very convoluted way to go, and I want to give those who will deal with this relatively simple instructions.
I will appreciate any help.