MSYS2静态链接输出二进制 [英] MSYS2 statically link output binary

查看:192
本文介绍了MSYS2静态链接输出二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以静态链接从MSYS2 gcc生成的.exe文件?我尝试了很多方法,但没有一个起作用.所有生成的.exe文件都需要我要删除的msys-2.0.dll.到目前为止,我尝试启用-ststic选项,-static-libgcc选项并将这些选项传递给-Wl,但是它们都不起作用.我尝试剥离二进制文件与否,但输出文件的大小没有区别.我知道我可以在MSYS1.0 gcc或Linux的mingw-w64中执行此操作,但是我不能在MSYS2.0中执行此操作.运行gcc -v之后,它显示工具链确实已使用--enable-static以及--enable-shared和--enable-shared-libgcc进行了编译.无论如何,我可以获得静态的libgcc库吗?

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?

推荐答案

好,我解决了.从MSYS2的文档中可以看出,MSYS2旨在通过使用公用的共享libc来减轻DLL的麻烦和错误.因此,无意创建静态链接的可执行文件.

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.

但是,您可以从pacman安装mingw-w64软件包,然后运行mingw64.exe来启动外壳程序,而不是msys2.exe.这样,您可以从bash而非MSYS2版本安装并运行原始的mingw-w64编译器套件.

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.

原始mingw-w64软件包生成的可执行文件是静态链接的.不需要msys-2.0.dll,而是需要无处不在的msvcrt.dll.

The executable generated by original mingw-w64 package is statically linked. Instead of requiring msys-2.0.dll, it requires ubiquitously available msvcrt.dll.

这篇关于MSYS2静态链接输出二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆