Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Qt doesn't build statically in CMake

Qt doesn't build statically in CMake

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
4 Posts 2 Posters 367 Views 1 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.
  • E Offline
    E Offline
    ewalve
    wrote on last edited by ewalve
    #1

    I want CMake to build Qt application portable for other PCs. However Qt builds unlike I both wanted and expected. I tried everything I had in my mind, for example i added lots of options to linker but nothing worked because Qt still requires standard C++ DLLs which means it makes complicated to start on other PCs.

    CMakeLists.txt:
    [Important Note]: this CMakeLists.txt is additional to the main one it means project name is defined in main CMakeLists.txt

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
    
    set(SOURCE_FILES src/main.cpp)
    find_package(Qt6Widgets REQUIRED)
    
    add_executable(${PROJECT_NAME}_client WIN32 ${SOURCE_FILES})
    
    
    if(WIN32)
        target_link_options(${PROJECT_NAME}_client PRIVATE -static -static-libgcc -static-libstdc++) #still requires lots of DLLs so the built app doesn't start on other PC
    endif()
    target_link_libraries(${PROJECT_NAME}_client Qt6::Widgets)
    
    if(WIN32)
        add_custom_command(
                TARGET ${PROJECT_NAME}_client POST_BUILD
                COMMAND ${WINDEPLOYQT_EXECUTABLE}
                ARGS "$<TARGET_FILE:${PROJECT_NAME}_client>" --dir $<TARGET_FILE_DIR:${PROJECT_NAME}_client> --release --compiler-runtime
                WORKING_DIRECTORY $<TARGET_FILE_DIR:${PROJECT_NAME}_client>
                COMMENT "Running windeployqt on ${PROJECT_NAME}_client executable"
        )
    endif()
    

    Main CMakeLists.txt (if needed to view):

    cmake_minimum_required(VERSION 3.5)
    project(HIDDENNAME)
    
    add_subdirectory(client)
    #add_subdirectory(server)
    

    What I used:
    [Qt version]: offline version of Qt6 (was used for Mingw64 toolchain)
    [OS]: Windows11
    [toolchain]: Msys2/Mingw64
    [Compilers]:

    • gcc (C compiler)
    • g++ (C++ compiler)
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You have to compile Qt statically by yourself and use this then when you compile your application

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      E 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        You have to compile Qt statically by yourself and use this then when you compile your application

        E Offline
        E Offline
        ewalve
        wrote on last edited by
        #3

        @Christian-Ehrlicher how to compile it? I can't see anywhere.
        [note]: this version of Qt was downloaded from msys2

        Christian EhrlicherC 1 Reply Last reply
        0
        • E ewalve

          @Christian-Ehrlicher how to compile it? I can't see anywhere.
          [note]: this version of Qt was downloaded from msys2

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ewalve said in Qt doesn't build statically in CMake:

          I can't see anywhere.

          https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2

          • Login

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