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

Qt6, MSVC: Can't compile example with statically build Qt

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 6.0.1
    • Build System
    • Windows10 x64
    • Windows

    Description

      RTA test downloads Qt src achive, compiles it statically and uses that build to compile an example. Gcc, clang and MinGW builds work fine, but the MSVC test has linker errors when compiling the example:

      Qt6Gui.lib(qplatformsystemtrayicon.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qplatformgraphicsbuffer.cpp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qplatformgraphicsbuffer.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qplatformgraphicsbufferhelper.cpp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qplatformgraphicsbufferhelper.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qsimpledrag.cpp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qsimpledrag.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qwindowsfontengine.cpp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qwindowsfontengine.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qwindowsfontenginedirectwrite.cpp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qwindowsfontenginedirectwrite.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qfontengine_ft.cpp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qfontengine_ft.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qshapedpixmapdndwindow.cpp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in mocs_compilation.cpp.obj
      Qt6Gui.lib(qshapedpixmapdndwindow.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in mocs_compilation.cpp.obj
         Creating library quickwidget.lib and object quickwidget.exp
      LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
      

      Steps to repro:

      Download and extract Qt6.0.1 sources, configure Qt:

      cmake 
      -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -GNinja 
      -DCMAKE_BUILD_TYPE=Release -DQT_BUILD_EXAMPLES=OFF -DBUILD_WITH_PCH=OFF 
      -DOPENSSL_ROOT_DIR=C:\openssl\include\.. -DFEATURE_system_zlib=OFF 
      -DPostgreSQL_ROOT=C:\Utils\postgresql\pgsql\lib\.. -DQT_BUILD_TESTS=OFF 
      -DBUILD_SHARED_LIBS=OFF C:\Users\qt\RTA\src-6.0.1 
      -DCMAKE_INSTALL_PREFIX:PATH=C:\Users\qt\RTA\src-6.0.1\qtbase
      

      Compile Qt: cmake --build . --parallel -> compilation ok (build log attached)

      Copy example qtdeclarative\examples\quick\quickwidgets\quickwidget out of the source tree to C:\Users\qt\RTA\tmp\quickwidget

      Add above built static Qt to PATH and set the CMAKE_PREFIX_PATH to [static_build_dir]/qtbase/lib/cmake

      Compile with cmake CMakeLists.txt and cmake --build . --parallel -> linker errors

      As said, same test with MinGW (cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Release -DQT_BUILD_EXAMPLES=OFF -DOPENSSL_ROOT_DIR=C:\openssl\include\.. -DFEATURE_system_zlib=OFF -DFEATURE_system_tiff=OFF -DFEATURE_system_freetype=OFF -DFEATURE_system_jpeg=OFF -DPostgreSQL_ROOT=C:\Utils\postgresql\pgsql\lib\.. -DQT_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF C:\Users\qt\RTA\src-6.0.1 -DCMAKE_INSTALL_PREFIX:PATH=C:\Users\qt\RTA\src-6.0.1\qtbase) works just fine, the quickwidget application is compiled without errors.

      SHA1: f57f0181262a836b97f2e18b585f9545f36ecd79

      Attachments

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

        Activity

          People

            qtbuildsystem Qt Build System Team
            joaijala Johanna Äijälä
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes