Reputation: 1198
I'm using a Facade DLL to a static lib. The Dll provides a small interface and resource management to be shared across multiple DLLs. The Dll-Header do expose stuff from the static library:
class DLL_EXPORT MyDllClass {
public:
/// ...
OneStaticLibClass * ptr;
};
The Problem is: if this should works I've to link the StaticLib to the DLL and the application using DLL. I didn't manage to export parts of the StaticLib correctly. I tried in the export headers:
class DLL_EXPORT OneStaticLibClass;
but that doesn't work... I still get:
undefined reference to OneStaticLibClass::~OneStaticLibClass(void)
undefined reference to OneStaticLibClass::operator<<(char const *)
Andy ideas how I can export parts of the static library with the DLL?
Thank you!
Upvotes: 5
Views: 2996
Reputation: 119847
You will need to create a .def file and pass it to the linker. DLLEXPORT is not necessary in this case.
The reason for this is the way symbols are resolved when using a static library. When you create a DLL, only those symbols needed by the DLL itself are searched, and object files containing these symbols are copied into the DLL. If the DLL code does not reference your destructor, it will not be included.
A .def file will tell the linker which functions are exported. Exported functions will be searched and pulled from the static library.
One downside of this process is that you need to use mangled C++ names in the .def file. Mangled names can be obtained with the dumpbin utility.
Upvotes: 4