Say I have 2 simple classes A
and C
, also I have global external variables in form of pointers to A
and C
. Code:
//global.h
#pragma once
#include "A.h"
#include "C.h"
struct A;
struct C;
extern A* external_a;
extern C* external_c;
/////////////////////////////////////////
//A.h
#pragma once
struct A {
void get();
};
/////////////////////////////////////////
//A.cpp
#include "A.h"
void A::get() {}
/////////////////////////////////////////
//C.h
#pragma once
# include "global.h"
struct C {
void doit();
};
/////////////////////////////////////////
//C.cpp
# include "C.h"
void C::doit() { external_a->get(); }
/////////////////////////////////////////
I listed only DLL code. The point was for DLL user to provide from (declare in) his EXE code say main.cpp global variables for my DLL code to use. So user is not in the same project while I want to use that external variables in multiple files inside my DLL project.
I get two errors from this code regarding unresolved external symbol "struct A * external_a"
I have tried to write __declspec(dllexport)
in class defenitions and after external
keyword. It does not help to fix the error. So I wonder what shall be done to be able to compile such project?