Qt doesn't build statically in CMake
-
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.txtset(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)
-
You have to compile Qt statically by yourself and use this then when you compile your application
-
You have to compile Qt statically by yourself and use this then when you compile your application
@Christian-Ehrlicher how to compile it? I can't see anywhere.
[note]: this version of Qt was downloaded from msys2 -
@Christian-Ehrlicher how to compile it? I can't see anywhere.
[note]: this version of Qt was downloaded from msys2@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