"Fabian" <Fa****@discuss ions.microsoft. comwrote in message
news:60******** *************** ***********@mic rosoft.com...
>I have a native singleton in a C++/CLI dll. To compile the dll itself I put
a
declaration of the instance variable into the cpp file (otherwise the
linker
complains with a LNK 2020).
I now want to use the singleton also from outside the dll project. So I
just
#include the header file in a file in another dll. It compiles but the
linker doesn't find the static variable (LNK2001).
Any suggestions?
Your immediate problem would be solved with a declaration tagged with
__declspec(dlli mport)... but that's a bad idea.
Write extern "C" wrappers for the functions you want to call from the DLL's
client. Sharing native C++ classes across module boundaries is a bad idea,
because it's almost impossible to get the exact same definition on both
sides, so you end up violating ODR and getting undefined behavior. Use
extern "C" functions instead, or DCOM, or use a managed class.