Is there any way to statically link the generated .exe file from MSYS2 gcc? I tried many ways, but none of them worked. All generated .exe files require msys-2.0.dll, which I want to get rid of. So far, I tried to enable -ststic option, -static-libgcc option and pass these options to -Wl, but non of them works. I tried to strip the binary or not, with no difference but the output file size. I know I can do this in MSYS1.0 gcc, or mingw-w64 from Linux, but I can not do this in MSYS2.0. After running gcc -v, it shows the tool chain was indeed compiled with --enable-static as well as --enable-shared and --enable-shared-libgcc. Is there anyway I can get static libgcc library?
相关问题
- Error building gcc 4.8.3 from source: libstdc++.so
- What are the recommended GNU linker options to spe
- What is the right order of linker flags in gcc?
- Why doesn't g++ -Wconversion warn about conver
- How to debug static dependency loading problems?
相关文章
- gcc/g++ gives me error “CreateProcess: No such fil
- Calls that precede a function's definition can
- How can I use gcc's -I command to add recursiv
- How do I know if std::map insert succeeded or fail
- How to specify gcc flags (CXXFLAGS) particularly f
- How to generate assembly code with gcc that can be
- Embedding a program's source code into its bin
- What is the purpose of “-Wa,option” in GCC? [close
I also had this problem - a very simple terminal program, utilizing only
stdio.h
andstring.h
, tended to raise "The code execution cannot proceed because msys-2.0.dll was not found. Reinstalling the program may fix this problem." in a normal terminal.Finally, this post helped resolved the issue - but there were some subtle problems, which I'll note here.
Now, my problem was this:
I started by installing MSYS2; apparently I had installed GCC in it.
Now, even when I changed to the MINGW64 terminal (and not the MSYS2 terminal), and recompiled, I would have had the same problem with msys-2.0.dll.
Finally, I thought of checking in the MINGW64 terminal:
Note, that this -
/usr/bin/gcc
- is the exact same path, that you get back, if you're in the MSYS2 shell.So, I tried to look for gcc again, in the MINGW64 shell:
Aha, so it turns out I do not have the
mingw64
gcc
installed - I've only had themsys
gcc
installed!So, just installed the
mingw64
gcc
- of course, from inside the MINGW64 (not the MSYS2) shell:After this, you need to close and re-open the MINGW64 shell; once you do that, you can see that:
... now that path to
gcc
for MINGW64 is/mingw64/bin/gcc
- while the path in MSYS2 remains/usr/bin/gcc
.Thus, if I now compile with
gcc
in MINGW64 shell, I compile with/mingw64/bin/gcc
, and now my resulting .exe can run in the usual Windows command prompt, without asking for msys-2.0.dll - which is great:)
Well, I solved it. From MSYS2's documents it says MSYS2 is designed to mitigate DLL hell and bugs by using a common, shared libc. Therefore, it is not intended to create statically linked executable.
However, you can install mingw-w64 package from pacman, and run mingw64.exe to launch the shell, instead of msys2.exe. By doing this, you can install and run original mingw-w64 compiler suite from bash, instead of the MSYS2 version.
The executable generated by original mingw-w64 package is statically linked. Instead of requiring msys-2.0.dll, it requires ubiquitously available msvcrt.dll.