What files of MinGW need to be deployed?

若如初见. 提交于 2019-12-25 07:46:52

问题


I compiled a Linux software in MinGW64 (MSYS2) on Windows with gcc-6.3.0 and gcc-gnat-6.3.0. I would like to assemble an installer package or zip file, that contains all necessary files. What parts of MinGW are required at a destination machine?

I don't want to ship a complete MSYS2/MinGW64, because it has 3 GiB! The executable has only 10 MiB.

I also won't demand a user to install MSYS2 and MinGW64, because it's a nightmare to install it on a Windows machine. The package manager (pacman) is not user friendly / usable for normal users.


Edit 1:

Normally, MinGW64 is not in my PATH. I have a script to add it depending on the selected MinGW version 32 vs. 64. The GCC used to compile the program is from the mingw32 or mingw64 directory.

I copied the binary to a separate directory: C:\Tools\GHDL\0.34dev-mingw64-llvm\bin

I used ldd.exe to inspect the executables:

C:\msys64\usr\bin\ldd.exe C:\Tools\GHDL\0.34dev-mingw64-llvm\bin\ghdl.exe
    ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x77020000)
    kernel32.dll => /c/Windows/system32/kernel32.dll (0x76f00000)
    KERNELBASE.dll => /c/Windows/system32/KERNELBASE.dll (0x7fefcf20000)
    ADVAPI32.dll => /c/Windows/system32/ADVAPI32.dll (0x7fefd6a0000)
    msvcrt.dll => /c/Windows/system32/msvcrt.dll (0x7fefd130000)
    sechost.dll => /c/Windows/SYSTEM32/sechost.dll (0x7feff310000)
    RPCRT4.dll => /c/Windows/system32/RPCRT4.dll (0x7fefe450000)
    SHELL32.dll => /c/Windows/system32/SHELL32.dll (0x7fefe580000)
    SHLWAPI.dll => /c/Windows/system32/SHLWAPI.dll (0x7fefe120000)
    GDI32.dll => /c/Windows/system32/GDI32.dll (0x7fefda60000)
    USER32.dll => /c/Windows/system32/USER32.dll (0x76e00000)
    LPK.dll => /c/Windows/system32/LPK.dll (0x7fefd110000)
    USP10.dll => /c/Windows/system32/USP10.dll (0x7fefd5d0000)

C:\msys64\usr\bin\ldd.exe C:\Tools\GHDL\0.34dev-mingw64-llvm\bin\ghdl1-llvm.exe
    ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x77020000)
    kernel32.dll => /c/Windows/system32/kernel32.dll (0x76f00000)
    KERNELBASE.dll => /c/Windows/system32/KERNELBASE.dll (0x7fefcf20000)
    ??? => ??? (0x6fe40000)
    libstdc++-6.dll => /c/Program Files/gettext-iconv/libstdc++-6.dll (0x6fc40000)
    libgcc_s_sjlj-1.dll => /c/Program Files/gettext-iconv/libgcc_s_sjlj-1.dll (0x6cec0000)
    msvcrt.dll => /c/Windows/system32/msvcrt.dll (0x7fefd130000)
    libwinpthread-1.dll => /c/Program Files/gettext-iconv/libwinpthread-1.dll (0x64940000)
    USER32.dll => /c/Windows/system32/USER32.dll (0x76e00000)
    GDI32.dll => /c/Windows/system32/GDI32.dll (0x7fefda60000)
    LPK.dll => /c/Windows/system32/LPK.dll (0x7fefd110000)
    USP10.dll => /c/Windows/system32/USP10.dll (0x7fefd5d0000)

I assume, the first executable ghdl.exe is OK, because it references only Windows DLLs. The second executable ghdl1-llvm.exe has four special entries:

  • libstdc++-6.dll => /c/Program Files/gettext-iconv/libstdc++-6.dll
  • libgcc_s_sjlj-1.dll => /c/Program Files/gettext-iconv/libgcc_s_sjlj-1.dll
  • libwinpthread-1.dll => /c/Program Files/gettext-iconv/libwinpthread-1.dll
  • ??? => ???

Questions:

  • Does the first mean, a user needs a C++ package? Is this VC++ 6.0 redistributable?
    Otherwise, there is a gettext package on Linux ...
  • I compiled ghdl, which is written in Ada, with llvm backend. I would expect two more dependencies like on Linux:

    • llvm 3.8
    • libgnat 6.3.0
  • OTOH, GHDL also has a libgrt.a file. How can I read the dependencies from that file?


Edit 2:

Oh, I think there are binding errors in the edit 1.
If I run ldd from within MinGW64 console, I see gettext bound to other files ...

E.g. libstdc++-6.dll => /mingw64/bin/libstdc++-6.dll (0x6fc40000)


回答1:


First of all, make sure you are actually building a native (MinGW) Windows application. The compiler you are using should be located in /mingw64/bin/ or /mingw32/bin. Run which gcc to make sure you are using the right compiler. Lots of MSYS2 problems boil down to people not knowing which compiler to use, so I always mention it.

The DLLs you need are determined by exactly what libraries your program uses and how it was compiled. So I can't just tell you what DLLs you will need. Instead, I will help you figure it out on your own.

The experimental method to figure this out is to just take the executable file you compiled, move it to a different folder outside of MSYS2, and try to run it by double-clicking on it. It will probably complain about some DLL missing. Copy that DLL from the appropriate bin directory inside MSYS2 (/mingw64/bin or /mingw32/bin) into the directory with your executable. Repeat this until your program runs successfully. Note that I am assuming that MSYS2 or other programs with similar DLLs are not on your PATH. You might want to reduce the number of folders in your PATH temporarily to be sure you are doing this correctly. For example, you could try running the program from a Command Prompt after running set PATH=.

Another method that I often use is to open my executable in Dependency Walker and see what DLLs it directly depends on.

Please note that on rare occasions, you might have a DLL that gets loaded at run time instead of when the program starts. The methods I mentioned above cannot detect that, and there is no general mechanism to do so.

Expanded answer for the new questions added to the question

The file libstdc++-6.dll is GCC's libstdc++. It implements the C++ standard library, providing things like std::string. The "VC++ 6.0 redistributable" would be some Microsoft product, which is very different.

Your second question is not a question. Maybe some of the libraries were statically linked instead of dynamically linked.

I don't know of any good way to read the dependencies of a static library file like libgrt.a. Static libraries are just a bundle of objects that have not been linked yet so a static library just has lists of undefined symbols that it needs, but it does not know which shared or static library will end up providing those symbols. I suggest compiling the static library it into an executable.



来源:https://stackoverflow.com/questions/42742020/what-files-of-mingw-need-to-be-deployed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!