I have two class that I want to import from a dynamic library. One off then work just fine. I can use the first one without any linking error, but the second one create an linking 2019 code error. I have no idea about what I'm doing wrong with the second one.
The problem happen only when I try to use the class.
There is the header file with and the definition off the class that create linking error :
Vertice.h //the class with linking error
#pragma once
#ifdef CGENGINE_EXPORTS
#define ENGINE_API __declspec(dllexport)
#else
#define ENGINE_API __declspec(dllimport)
#endif
constexpr char EMPTYCHAR = char(32);
class ENGINE_API Vertice
{
public:
Vertice(int color, char caracter);
~Vertice(void);
const bool operator != (const Vertice vertice);
public:
int color;
char caracter;
};
Vertice.cpp
#include "Vertice.h"
Vertice::Vertice(int color, char caracter) :
color(color), caracter(caracter)
{
}
Vertice::~Vertice(void)
{
}
const bool Vertice::operator!=(const Vertice vertice)
{
const unsigned int size = sizeof(Vertice);
for (int index = 0; index < size; index++)
{
char* self_byte = ((char*)this) + index;
char* vertice_byte = ((char*)&vertice + index);
if (*self_byte != *vertice_byte) { return false; }
} return true;
}
There is the error output :
Build started... 1>------ Build started: Project: Flappy Bird, Configuration: Debug Win32 ------ 1>Application.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Vertice::Vertice(int,char)" (__imp_??0Vertice@@QAE@HD@Z) referenced in function _main 1>Application.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Vertice::~Vertice(void)" (__imp_??1Vertice@@QAE@XZ) referenced in function _main 1>C:\Users\Jehud\source\repos\CGEngine\Debug\Flappy Bird.exe : fatal error LNK1120: 2 unresolved externals 1>Done building project "Flappy Bird.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ========== Build started at 9:22 PM and took 02,122 seconds ==========
I try to put both class declaration in the same header file and/or same cpp file. It give me the same error output.