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

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.7.1
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            docteam Qt Documentation Team
            Reporter:
            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