I created a C++ project in Visual Studio 2019. I added two files to it: MyClass.hpp
and MyClass.cpp
. Then I created a test project and added the original project as a reference.
If I doubleclick on the reference in the test project, I can see MyClass
. But if I try to run the tests, I get this error:
MyTest.obj : error LNK2019: unresolved external symbol "public: struct MyRef __thiscall MyClass::SetData(struct Data)" (?SetData@MyClass@@QAE?AUMyRef@@UData@@@Z) referenced in function "private: virtual void __thiscall MyTest_SetData_Test::TestBody(void)" (?TestBody@MyTest_SetData_Test@@EAEXXZ)
What do I wrong? Why is MyClass.cpp
not compiled, even if it is in the referenced project?
I can build the original project without error. I only get the link error, when I try to build the test project.
I came across this question about unresolved external symbol error, but it did not solve my issue. This is a Visual Studio specific problem.
If I add MyClass.cpp
to the test project manually, then it works. But I do not want to do that for each file, because my project may have many more cpp source files, not just this one. I would like to make it work using the "references" feature.
When I created the test project, I selected the original project as a reference.