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

CMake: Provide hints that users probably don't want to create shared libaries on iOS

XMLWordPrintable

    • iOS/tvOS/watchOS

      Background

      A user tried to modularize their project by putting shared code inside a library that can be linked to other targets in the same project. They used qt_add_library(MyLib SHARED ...) to create their library, which led to some cryptic errors on iOS:

      Undefined symbols for architecture arm64:
        "_main", referenced from:
            user_main_trampoline() in libqios_debug.a[arm64][6](qioseventdispatcher.mm.o)
      ld: symbol(s) not found for architecture arm64
      

       

      This led them to search for a way to exclude QIOSIntegrationPlugin from their library target. One such method was found at QTBUG-139942, but then the library cannot be linked to an executable that also uses Qt because then two copies of Qt would get loaded.

       

      Analysis

      In hindsight, "How to avoid linking these plugins that caused the undefined symbol error" is a manifestation of the XY problem. The same goes for "How to create a shared library for iOS" (QTBUG-139942).

      The actual problem was "How to correctly move this code out into a standalone library", and the solution for iOS is currently "Put it in a static library".

       

      Suggestion

      If someone tries to create a shared library that uses static Qt on iOS, let the build system give the user a heads-up: Warn that such a library can't be linked to other Qt-based targets, and suggest using a static library instead. This message should be suppressable with a flag, in the event they truly want a shared library.

      Benefits:

      • This would be much clearer than "undefined symbol for _main".
      • This would also alert users who (accidentally) create a shared library that only depends on Qt Core - this could currently build fine without warnings.

       

      Reference
      Attempting to build the example from QTBUG-139942 on WASM produces the following warnings from Emscripten:

      em++: warning: linking a library with `-shared` will emit a static object file.  This is a form of emulation to support existing build systems.  If you want to build a runtime shared library use the SIDE_MODULE setting. [-Wemcc]
      em++: warning: ignoring unsupported linker flag: `-soname` [-Wlinkflags]
      

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

            qtbuildsystem Qt Build System Team
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes