Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cross-compile from Linux Docker Container to Windows - run host qt binaries

Cross-compile from Linux Docker Container to Windows - run host qt binaries

Scheduled Pinned Locked Moved Solved General and Desktop
crosscompilingwindowsdockerxwincmake
3 Posts 1 Posters 209 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SebastianMS Offline
    SebastianMS Offline
    SebastianM
    wrote on last edited by SebastianM
    #1

    Hi,
    I want to move build process to container.
    I've created Dockerfile which downloads MSVC and winsdk includes and libraries (rust xwin does it well).
    Then I download correct version of Qt for msvc2019 and gcc64.
    I've reused my old CMake toolchain and with clang I successfully built protobuf (one of dependencies).
    However, when I tried to configure qml binary - it fails with attempt to execute qmlimports.exe (obviously it won't work on Linux).

    cmake -S /run/qml_app_src -B /run/qml_app_src/build -DCMAKE_PREFIX_PATH="/root/protobuf_src/install" -DCMAKE_BUILD_TYPE=Release -GNinja --toolchain /opt/cross/windows-cross.cmake --trace-expand --trace-redirect=/opt/temp/cmake_trace.log

    set(CMAKE_SYSTEM_NAME Windows)
    set(CMAKE_SYSTEM_PROCESSOR x86_64)
    set(CMAKE_CROSSCOMPILING ON)
    
    set(LLVM_BASE_DIR /usr/lib/llvm-19/bin)
    
    # Clang-cl as compiler
    set(CMAKE_C_COMPILER ${LLVM_BASE_DIR}/clang-cl)
    set(CMAKE_CXX_COMPILER ${LLVM_BASE_DIR}/clang-cl)
    set(CMAKE_RC_COMPILER ${LLVM_BASE_DIR}/llvm-rc)
    set(CMAKE_LINKER ${LLVM_BASE_DIR}/lld-link)
    set(CMAKE_MT ${LLVM_BASE_DIR}/llvm-mt) # Manifest tool
    set(CMAKE_RC_COMPILER ${LLVM_BASE_DIR}/llvm-rc)
    set(CMAKE_RC_COMPILER_INIT ${LLVM_BASE_DIR}/llvm-rc)
    #set(CMAKE_MT /bin/true)
    
    # Target triple
    set(triple x86_64-pc-windows-msvc)
    set(CMAKE_C_COMPILER_TARGET ${triple})
    set(CMAKE_CXX_COMPILER_TARGET ${triple})
    
    # MSVC paths (adjust versions as needed)
    set(MSVC_ROOT "/opt/winsdk/crt/")
    set(WINSDK_ROOT "/opt/winsdk/sdk/")
    
    # Linker flags
    set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld-19")
    set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld-19")
    
    set(CMAKE_C_FLAGS_INIT "-m64 -fms-compatibility /vctoolsdir ${MSVC_ROOT} /winsdkdir ${WINSDK_ROOT}")
    set(CMAKE_CXX_FLAGS_INIT "-m64 -fms-compatibility /vctoolsdir ${MSVC_ROOT} /winsdkdir ${WINSDK_ROOT}")
    set(CMAKE_EXE_LINKER_FLAGS_INIT "/manifest:no /machine:x64" )
    set(CMAKE_SHARED_LINKER_FLAGS_INIT "/manifest:no /machine:x64")
    
    # Use LLD as linker
    set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> /out:<TARGET> <LINK_LIBRARIES>")
    set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> /out:<TARGET> <LINK_LIBRARIES>")
    
    include_directories(SYSTEM ${WINSDK_ROOT}/include/)
    include_directories(SYSTEM ${WINSDK_ROOT}/include/um)
    include_directories(SYSTEM ${WINSDK_ROOT}/include/ucrt/)
    include_directories(SYSTEM ${WINSDK_ROOT}/include/shared/)
    
    #prefix in SYSTEM libs
    set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "/imsvc ")
    link_directories(${WINSDK_ROOT}/lib)
    link_directories(${WINSDK_ROOT}/lib/um/${CMAKE_SYSTEM_PROCESSOR})
    link_directories(${WINSDK_ROOT}/lib/ucrt/${CMAKE_SYSTEM_PROCESSOR})
    link_directories(${MSVC_ROOT}/lib/${CMAKE_SYSTEM_PROCESSOR})
    

    I placed include(/opt/qt/6.7.2/msvc2019_64/lib/cmake/Qt6/qt.toolchain.cmake) - inside above mentioned toolchain - after compilers are set. Now I see

    /opt/qt/6.7.2/msvc2019_64/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake(3355):  execute_process(COMMAND /opt/qt/6.7.2/msvc2019_64/./bin/qmlimportscanner.exe;-rootPath;/run/regappne_src/src;-cmake-output;-output-file;/run/regappne_src/build/src/.qt/qml_imports/regappne_conf.cmake;-importPath;/run/regappne_src/build/src;-importPath;/opt/qt/6.7.2/msvc2019_64/./qml WORKING_DIRECTORY /run/regappne_src/src RESULT_VARIABLE result )
    /opt/qt/6.7.2/msvc2019_64/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake(3360):  if(result )
    /opt/qt/6.7.2/msvc2019_64/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake(3361):  message(FATAL_ERROR Failed to scan target regappne for QML imports: permission denied )
    

    How to trigger usage of Linux Host Qt binaries during configuration and Windows Target Qt includes and libraries during building?

    1 Reply Last reply
    0
    • SebastianMS Offline
      SebastianMS Offline
      SebastianM
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • SebastianMS Offline
        SebastianMS Offline
        SebastianM
        wrote on last edited by
        #3

        Adding

        # ===== THE KEY FIX =====
        # Point to host Qt for build tools (moc, rcc, qmlimportscanner)
        set(QT_HOST_PATH "/opt/qt/6.7.2/gcc_64")
        
        # Point to target Qt for libraries/headers
        LIST(APPEND CMAKE_PREFIX_PATH "/opt/qt/6.7.2/msvc2019_64")
        

        solved problem with incorrect qmlimportscanner found. Now it uses gcc64 version.

        1 Reply Last reply
        0
        • SebastianMS SebastianM has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved