Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Statically linked executable requires dll
Servers for Qt installer are currently down

Statically linked executable requires dll

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.3k Views
  • 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.
  • K Offline
    K Offline
    Korsarq
    wrote on 29 Dec 2021, 11:03 last edited by
    #1

    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...

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 29 Dec 2021, 11:53 last edited by
      #2

      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.

      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
      • K Offline
        K Offline
        Korsarq
        wrote on 29 Dec 2021, 12:15 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kuzulis
          Qt Champions 2020
          wrote on 29 Dec 2021, 12:25 last edited by
          #4

          @Korsarq said in Statically linked executable requires dll:

          MSVCRT.DLL

          MSVCRT for MinGW? o_O

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ChrisW67
            wrote on 30 Dec 2021, 02:14 last edited by ChrisW67
            #5

            @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.

            1 Reply Last reply
            3

            1/5

            29 Dec 2021, 11:03

            • Login

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