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

WASM: libQt6Core.a is linked twice

XMLWordPrintable

    • WebAssembly

      Code
      CMakeLists.txt

      cmake_minimum_required(VERSION 3.16)
      project(MyProject)
      
      find_package(Qt6 COMPONENTS Core REQUIRED)
      qt_add_executable(MyProject main.cpp)
      
      target_link_libraries(MyProject PRIVATE Qt6::Core)
      target_link_options(MyProject PRIVATE -sMAIN_MODULE=1)
      

       

      main.cpp

      #include <QCoreApplication>
      
      int main(int argc, char* argv[])
      {
          QCoreApplication app(argc, argv);
          return app.exec();
      }
      

       

      Outcomes

      When built in Release mode, the following command is used:

      C:\emscripten-core\emsdk\upstream\emscripten\em++.bat -O3 -DNDEBUG -sMAIN_MODULE=1 -s MODULARIZE=1 -s EXPORT_NAME=MyProject_entry -s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,JSEvents,specialHTMLTargets,FS,callMain -s INITIAL_MEMORY=50MB -s MAXIMUM_MEMORY=4GB -s MAX_WEBGL_VERSION=2 -s WASM_BIGINT=1 -s STACK_SIZE=5MB -s ALLOW_MEMORY_GROWTH -sERROR_ON_UNDEFINED_SYMBOLS=1 -sFETCH CMakeFiles/MyProject.dir/main.cpp.o -o MyProject.js  C:/Qt/6.9.2/wasm_singlethread/lib/libQt6Core.a  C:/Qt/6.9.2/wasm_singlethread/lib/libQt6Core.a  -lembind  C:/Qt/6.9.2/wasm_singlethread/lib/libQt6BundledZLIB.a  C:/Qt/6.9.2/wasm_singlethread/lib/libQt6BundledPcre2.a
      

       

      Notice that C:/Qt/6.9.2/wasm_singlethread/lib/libQt6Core.a appears twice.

       

      Problems
      Normally, without -sMAIN_MODULE=1, the duplication doesn't cause any problems. However, a customer wanted their Qt app to be dlopen()'ed by a larger WASM app so they added the linker flag. Unfortunately, this caused duplicated symbol errors:

      wasm-ld: error: duplicate symbol: qDetectCpuFeatures
      >>> defined in C:/Qt/6.9.2/wasm_singlethread/lib/libQt6Core.a(qsimd.cpp.o)
      >>> defined in C:/Qt/6.9.2/wasm_singlethread/lib/libQt6Core.a(qsimd.cpp.o)
      
      wasm-ld: error: duplicate symbol: qt_cpu_features
      >>> defined in C:/Qt/6.9.2/wasm_singlethread/lib/libQt6Core.a(qsimd.cpp.o)
      >>> defined in C:/Qt/6.9.2/wasm_singlethread/lib/libQt6Core.a(qsimd.cpp.o)
      
      wasm-ld: error: duplicate symbol: qDumpCPUFeatures()
      >>> defined in C:/Qt/6.9.2/wasm_singlethread/lib/libQt6Core.a(qsimd.cpp.o)
      >>> defined in C:/Qt/6.9.2/wasm_singlethread/lib/libQt6Core.a(qsimd.cpp.o)
      
      ...
      

       

      Workarounds

      Manually run the command above with the duplicated entry removed. This causes the build to complete successfully.

       

      Alternatively, using qmake seems to work too (QMAKE_LFLAGS += -sMAIN_MODULE=1)

        1. WasmLinkerTest.zip
          0.6 kB
          Sze Howe Koh
        For Gerrit Dashboard: QTBUG-140211
        # Subject Branch Project Status CR V

            qt.webassembly qt.webassembly
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                There is 1 open Gerrit change