Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-59394

Q_INIT_RESOURCE cannot be called from main to initialize resources in a shared library

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.7.1
    • None
    • Windows 7

    Description

      The documentation (http://doc.qt.io/qt-5/resources.html and https://wiki.qt.io/QtResources) suggests to call Q_INIT_RESOURCE(name) from main to trigger loading of library resources. This works fine for static libraries. For shared libraries however, it generates a linker error (unresolved external symbol).

      I have spent a few hours trying to figure out why and I think the reason must be that the generated qInitResources_name() is not exported, i.e. it is not declared using Q_DECL_EXPORT. Therefore it cannot be seen from the application's main function.

      If I am right, I suggest that you mention this in the documentation, or even better; modifies the Q_INIT_RESOURCE macro to ensure that the generated function gets exported when generated inside a shared library.

      For now, the obvious workaround is to create a separate function in the shared library that uses Q_INIT_RESOURCE, make sure to export this function using Q_DECL_EXPORT and call it from main instead of using Q_INIT_RESOURCE directly.

      Attachments

        For Gerrit Dashboard: QTBUG-59394
        # Subject Branch Project Status CR V

        Activity

          People

            docteam Qt Documentation Team
            stian Stian Andre Olsen
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes