<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Qt doesn&#x27;t build statically in CMake]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">CMakeLists.txt:<br />
[Important Note]: this CMakeLists.txt is additional to the main one it means project name is defined in main CMakeLists.txt</p>
<pre><code>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 "$&lt;TARGET_FILE:${PROJECT_NAME}_client&gt;" --dir $&lt;TARGET_FILE_DIR:${PROJECT_NAME}_client&gt; --release --compiler-runtime
            WORKING_DIRECTORY $&lt;TARGET_FILE_DIR:${PROJECT_NAME}_client&gt;
            COMMENT "Running windeployqt on ${PROJECT_NAME}_client executable"
    )
endif()
</code></pre>
<p dir="auto">Main CMakeLists.txt (if needed to view):</p>
<pre><code>cmake_minimum_required(VERSION 3.5)
project(HIDDENNAME)

add_subdirectory(client)
#add_subdirectory(server)
</code></pre>
<p dir="auto">What I used:<br />
[Qt version]: offline version of Qt6 (was used for Mingw64 toolchain)<br />
[OS]: Windows11<br />
[toolchain]: Msys2/Mingw64<br />
[Compilers]:</p>
<ul>
<li>gcc (C compiler)</li>
<li>g++ (C++ compiler)</li>
</ul>
]]></description><link>https://forum.qt.io/topic/163995/qt-doesn-t-build-statically-in-cmake</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Apr 2026 13:03:37 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/163995.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 27 Dec 2025 17:34:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Qt doesn&#x27;t build statically in CMake on Sun, 28 Dec 2025 18:37:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ewalve">@<bdi>ewalve</bdi></a> said in <a href="/post/834934">Qt doesn't build statically in CMake</a>:</p>
<blockquote>
<p dir="auto">I can't see anywhere.</p>
</blockquote>
<p dir="auto"><a href="https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW" target="_blank" rel="noopener noreferrer nofollow ugc">https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW</a></p>
]]></description><link>https://forum.qt.io/post/834939</link><guid isPermaLink="true">https://forum.qt.io/post/834939</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 28 Dec 2025 18:37:29 GMT</pubDate></item><item><title><![CDATA[Reply to Qt doesn&#x27;t build statically in CMake on Sun, 28 Dec 2025 16:42:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> how to compile it? I can't see anywhere.<br />
[note]: this version of Qt was downloaded from msys2</p>
]]></description><link>https://forum.qt.io/post/834934</link><guid isPermaLink="true">https://forum.qt.io/post/834934</guid><dc:creator><![CDATA[ewalve]]></dc:creator><pubDate>Sun, 28 Dec 2025 16:42:59 GMT</pubDate></item><item><title><![CDATA[Reply to Qt doesn&#x27;t build statically in CMake on Sat, 27 Dec 2025 20:53:45 GMT]]></title><description><![CDATA[<p dir="auto">You have to compile Qt statically by yourself and use this then when you compile your application</p>
]]></description><link>https://forum.qt.io/post/834919</link><guid isPermaLink="true">https://forum.qt.io/post/834919</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 27 Dec 2025 20:53:45 GMT</pubDate></item></channel></rss>