Search code examples
c++qtvisual-c++lnk2001

LNK2001 on all private methods


I have a project with source code, and a TestProject in same solution.

The test file using GTest framework in the TestProject has got an #include of the header file Composite.h from main project.

In the body of the first GTest, I instantiate the Composite class declared in the Composite.h. This line gives a compile error LNK2001: unresolved external symbol on each of the private methods of the Composite class.

Code in the myTest.cpp file looks like that

#include "Composite.h"

TEST(testComposite, testCase1)
{
    Composite c;  // error LNK2001
    // my test here;
}

What's wrong with this instantiation ?

EDIT

I linked to the library containing the implementation of private methods in Composite class. Also, i tried alternatively to #inlcude the .cpp for the source code of this class. Either solution do not fix the problem.

EDIT -- QUESTION

Can this be that the folder with the moc files for the Composite classes and its parent class (with Q_OBJECT defined) are unseen ?

I tried adding in the Test Project properties' additionnal Directories the folder containing the moc files. This does not work either.


Solution

  • There should be nothing wrong with the instantiation. I assume that there is a Composite.cpp that contains your missing or unresolved code.

    You will need to add this Composite.cpp into your project or link your application to the library that contains the Composite.cpp