Export static lib symbols from a DLL

I am using a facade DLL for a static library. Dll provides a small interface and resource management for sharing in multiple DLLs. Dll-Header exposes material from a static library:

class DLL_EXPORT MyDllClass { public: /// ... OneStaticLibClass * ptr; }; 

The problem is this: if this works, I have to link StaticLib with the DLL and the application using the DLL. I was unable to export parts of StaticLib correctly . I tried in the export headers:

 class DLL_EXPORT OneStaticLibClass; 

but this does not work ... I still get:

 undefined reference to OneStaticLibClass::~OneStaticLibClass(void) undefined reference to OneStaticLibClass::operator<<(char const *) 

Andy's ideas, how can I export parts of a static library using a DLL?

Thanks!

+4
source share
1 answer

You will need to create a .def file and pass it to the linker. In this case, DLLEXPORT is not required.

The reason for this is how characters are resolved using a static library. When you create a DLL, only those characters are needed that are needed by the DLL itself, and object files containing these characters are copied to the DLL. If the DLL does not reference your destructor, it will not be included.

The .def file will tell the linker which functions will be exported. Exported functions will be searched and retrieved from the static library.

One drawback of this process is that you need to use the corrupted C ++ names in the .def file. Mangled names can be obtained using the dumpbin utility.

+3
source

Source: https://habr.com/ru/post/1500465/


All Articles