Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: QPluginLoader fails when using "debug" config

  1. #1
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question QPluginLoader fails when using "debug" config

    Hi,

    I'm using Qt 4.2.1 on Debian (etch) and I try to build a few plugins to extend my app's functionality. The problem I have is that QPluginLoader won't load my plugin if I compile the plugin (and the app of course) with "CONFIG += debug". In this case a subsequent QPluginLoader::errorString() just returns "Unknown Error".

    However, when I leave CONFIG blank or set it to "release" all works flawlessly. The same behaviour can be witnessed when I try the official example code "plugandpaint" - the static library is loaded by the application but the dynamic library isn't.

    Due to this I think that this is not related to my code but to Qt in general. Any idea?


    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    The first parameter of Q_EXPORT_PLUGIN2 macro must match the file name, so if there is "d" or "_debug" appended to plugin's name in debug mode, you have to make relevant change in your code.

  3. #3
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    True, but I'm using a static name as TARGET in my pro file. Even if I would use the dynamic version (as plugandpaint does)...

    Qt Code:
    1. contains(TEMPLATE,lib) {
    2. CONFIG(debug, debug|release) {
    3. mac:TARGET = $$member(TARGET, 0)_debug
    4. win32:TARGET = $$member(TARGET, 0)d
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

    ... it would only be relevant for Windoze and Mac OS, right?

    As I'm using this .pro file...

    Qt Code:
    1. TEMPLATE = lib
    2. CONFIG += plugin debug
    3. HEADERS += plugin.h
    4. SOURCES += plugin.cpp
    5. DESTDIR = ../bin/plugins
    6. TARGET = plugin
    To copy to clipboard, switch view to plain text mode 

    ... my usage of Q_EXPORT_PLUGIN2(plugin, Plugin) should be correct I think.

    para

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    ... my usage of Q_EXPORT_PLUGIN2(plugin, Plugin) should be correct I think.
    Yes, it should be OK in such situation.

    Nevertheless you could try Q_EXPORT_PLUGIN2(plugin_debug, Plugin) and rename your plugin to libplugin_debug.so.

  5. #5
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    I just tried it... doesn't work.

    Have a look at examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp. Even Trolltech uses a fixed value as target name in Q_EXPORT_PLUGIN2 although they consider the other host operating systems in their .pro file (see first code sample above). As stated above, adding debug to their CONFIG won't work either. Can you reproduce that on your machine? Maybe that gives us a clue...

    para
    Last edited by paradiza; 9th February 2007 at 22:54.

  6. #6
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    From the Qt docs:
    If you configure Qt to be built in both debug and release modes, but only build applications in release mode, you need to ensure that your plugins are also built in release mode. By default, if a debug build of Qt is available, plugins will only be built in debug mode. To force the plugins to be built in release mode, add the following line to the plugin's project file:
    CONFIG += release
    This will ensure that the plugin is compatible with the version of the library used in the application.
    What do they mean with the first sentence? Does the behaviour depend on the way Qt itself was built? I'm using the Debian package and hence have no influence on that I mean, as long as I set the same CONFIG values for the plugin and the app it should work, right?

    para

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    Have a look at examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp. Even Trolltech uses a fixed value as target name in Q_EXPORT_PLUGIN2 although they consider the other host operating systems in their .pro file (see first code sample above).
    Maybe something changed in Qt 4.2, but Qt 4.1 was very picky about that first parameter.

    Quote Originally Posted by paradiza View Post
    As stated above, adding debug to their CONFIG won't work either. Can you reproduce that on your machine?
    I've just rebuilt both plugandpaint application and extrafilterplugin in debug mode and it seems to work OK.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    I mean, as long as I set the same CONFIG values for the plugin and the app it should work, right?
    Right .

  9. #9
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by jacek View Post
    Maybe something changed in Qt 4.2, but Qt 4.1 was very picky about that first parameter.

    I've just rebuilt both plugandpaint application and extrafilterplugin in debug mode and it seems to work OK.
    Which Qt version and which OS are you using? Do you see libpnp_extrafilters.so being listed in the plugin dialog?

    Thanks

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    Which Qt version and which OS are you using?
    Qt 4.2.2 under PLD Linux.

    Quote Originally Posted by paradiza View Post
    Do you see libpnp_extrafilters.so being listed in the plugin dialog?
    Yes and I can use those filters.

    Did you add CONFIG += debug in extrafilters.pro or in plugandpaintplugins.pro (I did in the first one)?

  11. #11
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    I set it in
    1. basictools.pro (added "debug")
    2. extrafilters.pro (added "debug")
    3. plugandpaint.pro (added "CONFIG += debug")


    Didn't you change plugandpaint.pro?

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPluginLoader fails when using "debug" config

    Make sure that all components are built either in debug or release modes. Qt, plugin and your app should all be linked against each other (specifically the plugin should be built against the same version (debug or release) of Qt libraries). If in doubt, use ldd to check if the application and the plugin are linked against the same files when it comes to Qt dependency.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    Didn't you change plugandpaint.pro?
    Yes I did.

    I've built my Qt version in debug_and_release mode --- maybe that's why it works on my system?

  14. #14
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    Possibly. In this case the Qt docs would make more sense to me but I still wouldn't understand Trolltech for creating a dependency to the Qt build process itself!
    Can one determine how a given Qt installation was build...?

    On the other hand it still seems to me that this is unrelated to my problem as the configure option appears to be applicable for Mac OS only:
    -debug-and-release . Compile and link two versions of Qt, with and without debugging turned on. [Mac only]
    Maybe it's time for an official bug report to clarify this...?

    para
    Last edited by paradiza; 10th February 2007 at 09:29.

  15. #15
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by wysota View Post
    Make sure that all components are built either in debug or release modes. Qt, plugin and your app should all be linked against each other (specifically the plugin should be built against the same version (debug or release) of Qt libraries). If in doubt, use ldd to check if the application and the plugin are linked against the same files when it comes to Qt dependency.
    So you confirm what jacek says: if my Qt installation was built with "-release" instead of "-debug-and-release" there will never be a chance to compile my app and its plugins in debug mode because the Qt libs are not available for that mode, right?

    How could they design such a dependency? I understand that the plugin verification needs to ensure that app and plugin have to be compiled the same way, but it should not care about Qt itself in my opinion...

    para

  16. #16
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Exclamation Re: QPluginLoader fails when using "debug" config

    Ok, now I followed wysota's advice. The Qt debugging symbols are installed of course which means that, if I take libQtCore.so as an example, I have these to versions on my machine:
    • libQtCore.so.4.2.1
    • libQtCore.so.4.2.1.debug


    No my (possibly silly) question: how to tell Qt to link against the .debug version when I compile my project using the debug flag? ldd shows that the release versions are still being used which explains the issue here...

    Thanks

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    How could they design such a dependency?
    In this case "they" is people who designed the dynamic linker in your system.

    I understand that the plugin verification needs to ensure that app and plugin have to be compiled the same way, but it should not care about Qt itself in my opinion...
    It's not about plugin verification. If you link your app against release version of Qt and the plugin against a debug version of Qt then you'd end up with linking two different Qt libraries (or sets of libraries) with the application. As the release and debug versions expose the same symbols, you'd end up with a relocation error because all Qt symbols would be defined in two copies. That's why the linker will deny dlopening such a dynamic dependency. So it's not Qt that enforces the limitation but the design of how dynamic linkers work.

    Quote Originally Posted by paradiza View Post
    No my (possibly silly) question: how to tell Qt to link against the .debug version when I compile my project using the debug flag?
    The ".debug" file is not a library, it's just a set of symbols that are loaded when using a debugger. I don't know exactly how this works, but probably there are some differences between a file that has its ".debug" shadow and one that doesn't (at least such libs differ, so I guess there is a reason for that).

  18. #18
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    Well, thinking a bit more about the linker system I agree with you

    Quote Originally Posted by wysota View Post
    If you link your app against release version of Qt and the plugin against a debug version of Qt then you'd end up with linking two different Qt libraries (or sets of libraries) with the application.
    True, but this is not what I do. I link both parts (app and plugin) against the same version of Qt. The problem is that I don't know whether it was built using "-debug-and-release". Any idea how this can be solved?

    Regards

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader fails when using "debug" config

    Quote Originally Posted by paradiza View Post
    On the other hand it still seems to me that this is unrelated to my problem as the configure option appears to be applicable for Mac OS only
    Mac only? I must be blind So it seems that my Qt was built in release mode after all.

    I've just checked configure's options on windows and -debug-and-release is available there too, so certainly it's not "Mac only".

  20. #20
    Join Date
    Feb 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader fails when using "debug" config

    Interesting, that's what configure -help shows...
    Anyway, it seems that I've to find out how the Debian package maintainers built Qt and/or how this is going to work in conjunction with proper plugin development.

    Thanks so far guys! I'll let you know any progress but please don't hesitate to post more ideas here

    Bye

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.