Search code examples
c++linkerqt4dllexport

Dynamic library linkage issue in Windows


I have a problem with windows dynamic libraries. I've written a shared widget library in Linux using Qt/C++. Everything is ok and I can link every application against my library. But in Windows same code compiles, but any application can't use it. I'm getting a lot of linker errors of type undefined reference to ... which are all implemented in library.

I found that in Windows, symbol table of code is not exported to binary by default. I have to specify which function I want to be visible in final dll. But I can't manage to find a way to doing that.

Following this instructions, I add Q_DECL_EXPORT to all class declarations. but it doesn't work for me.


Solution

  • You should add MYSHAREDLIB_EXPORT to your class declarations, not Q_DECL_EXPORT. Also from the link your provided, which you define accordingly.

    If you add Q_DECL_EXPORT, you tell the compiler to generate code for that class in every module that includes the header, not to expect the class to be exported in another library.