Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Statically linked executable requires dll



  • I am building an executable with only static libraries, but when I try to run the executable I get an error for missing dlls.

    Here is my linker command:

    g++ -mwindows -static -LC:\Qt\6.2.2\mingw_64\lib -o out/TlvTool out/Src/Main.o out/Src/MainWindow/MainWindow.o out/Src/TlvParserWindow/TlvParserWindiw.o out/Src/TlvParser/TlvParser.o out/Src/MainWindow/MainWindow.moc.o out/Src/TlvParserWindow/TlvParserWindow.moc.o C:\Qt\6.2.2\mingw_64\lib\libQt6Core.a C:\Qt\6.2.2\mingw_64\lib\libQt6Gui.a C:\Qt\6.2.2\mingw_64\lib\libQt6Widgets.a

    I even added -static to disable dlls, also specified the full path to the libraries to make sure it uses static libraries..

    With Dependency Walker I see - QT6CORE.DLL, QT6WIDGETS.DLL, KERNEL32.DLL and MSVCRT.DLL. I can't understand wy it requires those dlls...


  • Lifetime Qt Champion

    You also have to compile your Qt as static libs. But why do you want this at all? Use windeployqt to make sure that all required libs are properly installed.



  • Thanks. I just wanted a simple executable file, with no dependencies. I thought that those libraries are build statically, but it appears that's not the case. Thanks for pointing out windeployqt, I didn't know about it. Will give it a try later today.


  • Qt Champions 2020

    @Korsarq said in Statically linked executable requires dll:

    MSVCRT.DLL

    MSVCRT for MinGW? o_O



  • @Korsarq said in Statically linked executable requires dll:

    KERNEL32.DLL and MSVCRT.DLL

    Any Windows application will depend on the first (directly or indirectly): it is the Windows base API (along with USER32.dll, GDI32.dll etc.).
    Almost any Windows application with components built in C/C++ will depend on the Microsoft Visual C Run Time (MSVCRT): it is the C standard library. MinGW also uses this library.
    Both are part of Windows, not part of your application.

    I thought that those libraries are build statically, but it appears that's not the case.

    In the default Qt build those libraries (e.g. libQt6Widgets.a) are stubs that provide the linker with information to connect your application to the corresponding dynamic library at run time.

    If you build Qt statically (which you are not doing) then these libraries will contain the actual Qt executable code. Your linked application binary will include this code directly and grow substantially in size. These static Qt libraries will still have dependencies on dynamically loaded (shared) Windows components like KERNEL32.dll.


Log in to reply