Search code examples
c++visual-studio-2013includeunresolved-external

Unresolved reference to constructor which is defined


I am getting an unresolved external symbol "public: __thiscall TestLanguage::TestLanguage(void)" (??0TestLanguage@@QAE@XZ) referenced in function _main

The TestLanguage constructor is defined as far as I can see, however obviously the compiler can't see it. My only conclusion is that there is some sort of inclusion problems (e.g. circular includes).

I have made a diagram of the includes for each translation unit below, however I can't see any problems. Any guidance would be appreciated.

Includes:

Test.cpp
    Expression.h
        Operation.h
        Token.h
    CPU.h
        Operation.h
    TestLanguage.h
        ILanguage.h
        TLOperators.h
            IOperator.h
                Operation.h
                Token.h

TestLanguage.cpp
    TestLanguage.h
        ILanguage.h
        TLOperators.h
            IOperator.h
                Operation.h
                Token.h

TLOperators.cpp
    TLOperators.h
        IOperator.h
            Operation.h
            Token.h
    Expression.h
        Operation.h
        Token.h
    CPU.h
        Operation.h

CPU.cpp
    CPU.h
        Operation.h
    Operation.h

Expression.cpp
    Expression.h
        Operation.h
        Token.h
    Util.h
    IOperator.h
        Operation.h
        Token.h
    CPU.h
        Operation.h
    ILanguage.h

Operation.cpp
    Operation.h

Token.cpp
    Token.h

Solution

  • After attempting to create a MCVE as suggested by @inetknght (thanks BTW), I discovered that it was actually a bug in Visual Studio Express 2013. I copied all my source files to a new project, so I could keep removing stuff to get the smallest example, however it compiled fine in the new project.

    When attempting to fix the original project, I cleaned the solution, manually deleted the object files, deleted the .sdf file in the project. None of that worked. Then I tried removing the TestLanguage.cpp file from the project and adding it back - and it worked.

    Hopefully this will help any others who experience this.