LNK2019: unresolved external symbol in VS unit-testing

后端 未结 4 1709
忘了有多久
忘了有多久 2021-02-19 19:40

I get the error as stated in the title. I ensured the following:
- The Include directory, include library and additional include directory are set correctly
- In the pro

4条回答
  •  故里飘歌
    2021-02-19 20:04

    I know this is very late but let me explain why including the .cpp file fixes the issue.

    #include "../LifeLib/StornoTafel.h"
    
    ...
    
    LifeLib::StornoTafel stornoTafel_; // Throws unresolved external symbol
    

    Your unit test project exists outside of your application, you have provided references to the header files which provide the declarations of your types and methods but not their definitions.

    By placing references to the .cpp files the compiler can actually get the declarations of these signatures:

    #include "../LifeLib/StornoTafel.h"
    #include "../LifeLib/StornoTafel.cpp"
    
    ...
    
    LifeLib::StornoTafel stornoTafel_; // Works perfectly
    

    The simplest solution is to simply duplicate your header file reference and change .h to .cpp

提交回复
热议问题