How to build static Qt 6.4 for Windows?
-
I am a noob, so please excuse ^^
I followed this tutorial here since I was not able to find a tutorial within Qt documentation:
https://decovar.dev/blog/2018/02/17/build-qt-statically/I ran this command to build qt:
configure.bat -static -release -no-pch -prefix "d:\path\to\qt\5.15.2-static" -skip qtwebengine -nomake tests -nomake examples
However, it seems the above method is meant only for Qt 5, not 6. when i follow the above method i get this error after running the built app:
Is there any resource/tutorial on how to build Qt 6.4.2 static? Thanks.
-
I am a noob, so please excuse ^^
I followed this tutorial here since I was not able to find a tutorial within Qt documentation:
https://decovar.dev/blog/2018/02/17/build-qt-statically/I ran this command to build qt:
configure.bat -static -release -no-pch -prefix "d:\path\to\qt\5.15.2-static" -skip qtwebengine -nomake tests -nomake examples
However, it seems the above method is meant only for Qt 5, not 6. when i follow the above method i get this error after running the built app:
Is there any resource/tutorial on how to build Qt 6.4.2 static? Thanks.
-
@rnayabed You need to deploy the DLL that provides std::pmr::get_default_resource(), or build that into your static binary.
-
It looks like you've built Qt with MinGW and then used CMake to build your project. I had a similar problem recently where building with qmake produced an executable that was able to launch without requiring any DLLs, while CMake-produced executable was complaining about missing DLLs, similar to how yours does.
So if you are in fact using CMake, my bet is that you need to do something like this in your project:
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
Looking at the std::pmr::get_default_resource symbol, it seems that your application is missing exactly that - a C++ runtime. And it could also be that you need to enforce C++17 standard in your project.
It is also possible that you'll get more DLLs erorrs after that, like missing zstd DLL for example. In that case you'll need to link to those too (with
target_link_libraries()
in case of CMake). -
It looks like you've built Qt with MinGW and then used CMake to build your project. I had a similar problem recently where building with qmake produced an executable that was able to launch without requiring any DLLs, while CMake-produced executable was complaining about missing DLLs, similar to how yours does.
So if you are in fact using CMake, my bet is that you need to do something like this in your project:
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
Looking at the std::pmr::get_default_resource symbol, it seems that your application is missing exactly that - a C++ runtime. And it could also be that you need to enforce C++17 standard in your project.
It is also possible that you'll get more DLLs erorrs after that, like missing zstd DLL for example. In that case you'll need to link to those too (with
target_link_libraries()
in case of CMake).Here is a configure line I'm using to build Qt 6.4.3 statically on Windows (and please remember to respect the license! Static builds usually mean commercial license of Qt!):
..\qt-everywhere-src-6.4.3\configure.bat -static -static-runtime -plugin-manifests -no-openssl -schannel -c++std c++20 -dbus-runtime -confirm-license -release -nomake examples -nomake tests -prefix ..\6.4.3 -no-icu -no-glib -qt-doubleconversion -qt-pcre -qt-zlib -qt-freetype -qt-harfbuzz -qt-libpng -qt-libjpeg -qt-sqlite -qt-tiff -qt-webp -skip qtcoap -skip qtopcua -skip qtscxml -skip qtwebengine -skip qt3d -skip qtconnectivity -skip qtlanguageserver -skip qtpositioning -skip qtsensors -skip qt5compat -skip qtdatavis3d -skip qtlottie -skip qtquick3d -skip qtserialbus -skip qtwebview -skip qtactiveqt -skip qtquick3dphysics -skip qtserialport -skip qtquicktimeline -skip qtwayland -skip qtcharts -skip qthttpserver -skip qtremoteobjects -skip qtspeech -skip qtwebchannel -skip qtmultimedia cmake --build . --parallel cmake --install .
Mind you, I am using MSVC to build, I am not sure if the same will work for MinGW.