jeudi 25 octobre 2018

Error while importing/exporting a variable (LNK2001)

I am trying to export/import a variable between exe and a dll. A.h is a file which is common to both.I am trying to set the variable in a file B.cpp compiled in exe and retrieve the variable in C.cpp compiled in dll.

In A.h

#ifdef VAL_DLLEXPORT
extern __declspec(dllexport) int* val;
#else
extern __declspec(dllimport) int* val;
#endif

B.h

#pragma push_macro("VAL_DLLEXPORT")
#define VAL_DLLEXPORT
#include <A.h>
#pragma pop_macro("VAL_DLLEXPORT")

B.cpp

int* val = nullptr;    //globally
int* val = someval     // In a function;

C.cpp

#pragma push_macro("VAL_DLLEXPORT")
#include <A.h>
#pragma pop_macro("VAL_DLLEXPORT")

and using val in some function

I am getting error C.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int * val"

I would really appreciate, any help or atleast some advice, where I can learn more about this problem.

Aucun commentaire:

Enregistrer un commentaire