Some details on my configuration + the problem:
  • I use the CMake Windows_Export_All_Symbols feature as explained here, and I don't worry about declspecs (dllimport/dllexport) any more.
  • As the title says, I use the new function-pointer approach for signals/slosts, to ensure type-safety at compile time.
  • When the signals/slots are in the same DLL, things are fine. Otherwise I get
    Qt Code:
    1. unresolved external symbol "public: static struct QMetaObject const top::level1::mtree::MyWidget::staticMetaObject"
    To copy to clipboard, switch view to plain text mode 
    - I don't believe namespace is a problem.
.

What have I researched, discovered and tried so far?
  • As stated in the CMake blog, the dll export feature of CMake doesn't work for static const members. They recommend "dllimport/dllexport" on those variables.
  • So I tried the solution from Qt (also mentioned in other blogs including this forum), like so:


Qt Code:
  1. #ifdef myWidget_DLL
  2. #define myWidget_DLL_EXPORT Q_DECL_EXPORT
  3. #else
  4. #define myWidget_DLL_IMPORT Q_DECL_IMPORT
  5. #endif
  6.  
  7. class myWidget_DLL_EXPORT MyWidget : public QDockWidget { ... };
  8.  
  9. # CMakeLists.txt entry to activate my macros
  10. add_definitions (-DmyWidget_DLL)
To copy to clipboard, switch view to plain text mode 
But this doesn't work because CMake already does something like this, and myWidget_DLL_EXPORT in the class declaration is treated like a class/type, and not a macro.

So, how do I selectively export / import
Qt Code:
  1. QMetaObject const top::level1::mtree::MyWidget::staticMetaObject
To copy to clipboard, switch view to plain text mode 
the variable found in moc_MyWidget.cpp. I tried exporting it from the moc_ file itself as a prototype, but it doesn't work - the compiler thinks I am trying to redefine the static meta object. What am I doing wrong? How do I resolve this. The constraint is that I don't want to close the CMake dll export feature, unless that is my last resort. Any pointers or suggestions is greatly appreciated.