[Qt-interest] From plugin to static

jjDaNiMoTh jjdanimoth at gmail.com
Wed Dec 9 19:55:13 CET 2009


Following the recent thread about static linking to qt, I was tempted
to see what happen with static linking instead of dynamic loading of
plugins. My program is GPL, so I don't have any licensing issue.

It is organized as:

core
+
++= Plugins
++++=Loader
++++= Plug1
++++++=Loader
++++++=SubPlug1
++++++=SubPlug2
++++= Plug2
++++++=Loader
++++++=SubPlug1
++++= Plug3
...
++= Library
...


It is recursive, so the core loads the class Loader, which for every
directory (Plug1, Plug2,Plug3..) loads its Loader which loads its
plugins. The dynamic loader approach works very well, but as I said
before I want to try a static approach: I still want dynamic link to
qt library, but I want that all plugins and my Library built static.
It is possible or my design lack something?

For testing, I done this: I've added CONFIG += staticlib in every
plugin and Library .pro, and CONFIG += static in the core .pro. After
this, in a mainwindow.cpp in core/ directory I added the
Q_IMPORT_PLUGIN macroes, one for every "loader" (loader of Plug1,
Plug2, Plug3..). In each Loader, I added Q_IMPORT_PLUGIN macro for
every SubPlug.

Then, I've added to core.pro a line like
LIBS += -LdirOfPlugins -lLoaderPlug1 -lLoaderPlug2 -lLoaderPlug3
-lPlug1SubPlug1 -lPlug1SubPlug2 [...]

Now, All things compiles fine (wow!), and all things are installed
correctly under dirOfPlugins ( I see a lot of .a, and a lot of .dylib
-- Why .dylib? I'm compiling all static..) but I get an error from the
linker. It complaints about a lot of missing reference:

"qt_plugin_instance_Plug1SubPlug1()", referenced from:
__Z37qt_plugin_instance_Plug1SubPlug1v$non_lazy_ptr in
libLoaderPlug1.a(moc_loaderPlug1.o)

The linker line is like the following:
g++ -headerpad_max_install_names -all_load -arch ppc -o
../../TheNatManagementSoftware main.o mainwindow.o moc_mainwindow.o
-F/Library/Frameworks -L/Library/Frameworks -L./libraryDir -llibrary
-LdirOfPlugins -l-lLoaderPlug1 -lLoaderPlug2 -lLoaderPlug3
-lPlug1SubPlug1 -lPlug1SubPlug2 [...] -framework QtGui -framework
QtCore

(I'm on OSX)

What I am missing? Because, in others line, I see that someone set the
preprocessor flag -DQT_SHARED and -DQT_STATICPLUGIN ? I want only
-DQT_STATICPLUGIN..

Many thanks
-- 
Key Fingerprint
4588 F931 A6E7 C7D5 A302  3064 12EB E87F 9B28 A9D2



More information about the Qt-interest-old mailing list