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

Fix linkage of static network bearer plugins

    XMLWordPrintable

    Details

    • Type: User Story
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Build System
    • Labels:
      None

      Description

      When building qtdeclarative as static libraries with Qt6 + CMake

      you get duplicate symbol errors like:

      inking CXX executable /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/bin/qmlprofiler
      FAILED: /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/bin/qmlprofiler 
      : && /usr/bin/c++  -g   tools/qmlprofiler/CMakeFiles/qmlprofiler.dir/qmlprofiler_autogen/mocs_compilation.cpp.o tools/qmlprofiler/CMakeFiles/qmlprofiler.dir/commandlistener.cpp.o tools/qmlprofiler/CMakeFiles/qmlprofiler.dir/main.cpp.o tools/qmlprofiler/CMakeFiles/qmlprofiler.dir/qmlprofilerapplication.cpp.o tools/qmlprofiler/CMakeFiles/qmlprofiler.dir/qmlprofilerclient.cpp.o tools/qmlprofiler/CMakeFiles/qmlprofiler.dir/qmlprofilerdata.cpp.o tools/qmlprofiler/CMakeFiles/qmlprofiler.dir/__/__/qt_Network_qgenericbearer.cpp.o tools/qmlprofiler/CMakeFiles/qmlprofiler.dir/__/__/qt_Network_qconnmanbearer.cpp.o tools/qmlprofiler/CMakeFiles/qmlprofiler.dir/__/__/qt_Network_qnmbearer.cpp.o  -o /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/bin/qmlprofiler  -Wl,-rpath,:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/lib/libQt6Core.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/lib/libQt6QmlDebug.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/lib/libQt6QmlDebug.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/lib/libQt6Network.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/plugins/bearer/libqgenericbearer.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/plugins/bearer/libqconnmanbearer.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/plugins/bearer/libqnmbearer.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/lib/libQt6Network.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/plugins/bearer/libqgenericbearer.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/plugins/bearer/libqconnmanbearer.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/plugins/bearer/libqnmbearer.a  -lgssapi_krb5  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/lib/libQt6DBus.a  /usr/lib/x86_64-linux-gnu/libdbus-1.so  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/lib/libQt6PacketProtocol.a  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/lib/libQt6Core.a  /usr/lib/x86_64-linux-gnu/libz.so  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/src/3rdparty/harfbuzz/libQtHarfBuzz.a  -lpthread  /usr/lib/x86_64-linux-gnu/libdouble-conversion.so  -lm  /usr/lib/x86_64-linux-gnu/libicui18n.so  /usr/lib/x86_64-linux-gnu/libicuuc.so  /usr/lib/x86_64-linux-gnu/libicudata.so  /usr/lib/x86_64-linux-gnu/libpcre2-16.so  /usr/lib/x86_64-linux-gnu/libzstd.so  -ldl  /usr/lib/x86_64-linux-gnu/libglib-2.0.so  /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/src/corelib/CMakeFiles/Core_resources_mimetypes.dir/.rcc/qrc_mimetypes.cpp.o && :
      /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/plugins/bearer/libqconnmanbearer.a(mocs_compilation.cpp.o):(.data.rel.ro+0x200): multiple definition of `QBearerEngineImpl::staticMetaObject'
      /home/alex/Dev/qt/qt5_cmake/qtbase_built_static_developer/plugins/bearer/libqgenericbearer.a(mocs_compilation.cpp.o):(.data.rel.ro+0x0): first defined here
      

      With qmake it coincidentally works, because the linker discards the symbols. The command line for qmake is:

      g++ -Wl,--enable-new-dtags -Wl,--gc-sections -o /home/alex/Dev/qt/qt514_built_static/qtbase/bin/qmlprofiler .obj/main.o .obj/qmlprofilerapplication.o .obj/commandlistener.o .obj/qmlprofilerdata.o .obj/qmlprofilerclient.o .obj/qmlprofiler_plugin_import.o .obj/moc_qmlprofilerapplication.o   /home/alex/Dev/qt/qt514_built_static/qtbase/plugins/bearer/libqconnmanbearer.a /home/alex/Dev/qt/qt514_built_static/qtbase/plugins/bearer/libqgenericbearer.a /home/alex/Dev/qt/qt514_built_static/qtbase/plugins/bearer/libqnmbearer.a /home/alex/Dev/qt/qt514_built_static/qtbase/lib/libQt5DBus.a /usr/lib/x86_64-linux-gnu/libdbus-1.so /home/alex/Dev/qt/qt514_built_static/qtbase/lib/libQt5QmlDebug.a /home/alex/Dev/qt/qt514_built_static/qtbase/lib/libQt5Network.a -lgssapi_krb5 /home/alex/Dev/qt/qt514_built_static/qtbase/lib/libQt5PacketProtocol.a /home/alex/Dev/qt/qt514_built_static/qtbase/lib/libQt5Core.a -lm /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/x86_64-linux-gnu/libdouble-conversion.so /usr/lib/x86_64-linux-gnu/libicui18n.so /usr/lib/x86_64-linux-gnu/libicuuc.so /usr/lib/x86_64-linux-gnu/libicudata.so /usr/lib/x86_64-linux-gnu/libdl.so /usr/lib/x86_64-linux-gnu/libpcre2-16.so /usr/lib/x86_64-linux-gnu/libzstd.so /usr/lib/x86_64-linux-gnu/libgthread-2.0.so /usr/lib/x86_64-linux-gnu/libglib-2.0.so -lpthread
      

      Note that the plugin import macros are in 3 files in CMake, but in one file in qmake, that's why everything coincidentally worked.

      The duplicate symbols appear because we run moc 3 times on QBearerEngineImpl in /Volumes/T3/Dev/qt/qt5_cmake/qtbase/src/plugins/bearer/qbearerengine_impl.h which generates 3 sets of symbols with the same names for each separate bearer plugin.

      The proper fix would be to move qbearerengine_impl.h / QBearerEngineImpl into QtNetwork, so that moc is run only once, and the moc definitions are shared for each of the plugins.

      A temporary workaround for CMake is to currently disable linkage of 2 of the 3 bearer plugins.

        Attachments

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

          Activity

            People

            Assignee:
            shausman Simon Hausmann
            Reporter:
            alexandru.croitor Alexandru Croitor
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews