Considering it’s a common issue, what could be the source of this error if one uses this file logic:
- Utils.h: declare
bool Dummy(); - Utils.cpp: define
bool Dummy() {return true;} - ClassA.h : an irrelevant
class A { bool sheet; public: A(); }; -
ClassA.cpp: the irrelevant code:
#include "Utils.h" #include "ClassA.h" A::A() { sheet = Dummy(); }Note: all header files contain the guard
#pragma oncemacro.
The error: something like this
Error 2 error LNK2028: unresolved token (0A00000B) "bool __clrcall Dummy(void)"
Error 3 error LNK2019: unresolved external symbol "bool __clrcall Dummy(void)" .... in ClassA.obj
You are compiling the ClassA.cpp file with /clr in effect, generating managed code. Your Dummy() function however was compiled without /clr, making the calling convention __cdecl. The linker notices the discrepancy, it can’t find the managed implementation for Dummy.
You must tell the compiler that Utils.cpp was built to native code. Fix ClassA.cpp like this: