Since you are creating a separate copy of the variable in each compiled file. Then they collide at the binding stage. Remember that the preprocessor reads in all header files and makes one large file of them. Therefore, every time this large file is compiled, another identical copy of gMemoryManager .
You need to use extern and define it in a single file without a header.
In your header file
extern DLL_EXPORT MemoryManager* gMemoryManager;
In one of your C ++ files
DLL_EXPORT MemoryManager * gMemoryManager;
By the way, I donβt know what DLL_EXPORT does, I just assume that it needs to go in both places.
user181548
source share