我可以将 MSVCRT 与 mingw 静态链接吗?
我有一个在 Windows 上用 mingw 编译的 C 程序。它工作正常,但需要 MSVCRT.DLL
。我想静态链接它(就像我在 Visual Studio 中可以做的那样)。这可能吗?
我尝试将 -static
标志设置为 gcc
,但它没有做出任何更改。
如果 C++ 程序也使用标准 C++ 库呢?
I have C program I compile with mingw
on Windows. It works fine but requires MSVCRT.DLL
. I want to link that statically (like I can do in Visual Studio). Is this possible?
I tried -static
flag to gcc
and it didn't make any change.
What about C++ program using also standard C++ library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信 MinGW 出于版权原因不使用静态运行时库。
您也许可以尝试使用 newlib (http://sourceware.org/newlib/) 创建一个可执行文件不链接到
msvcrt.dll
I believe that MinGW doesn't use the static runtime library for copyright reasons.
You can maybe try to use newlib (http://sourceware.org/newlib/) to create an executable that doesn't link to
msvcrt.dll
我自己花了一段时间搜索这个,我发现了 这篇文章< /a> 介绍正在进行中的 Mingw32 Alternate C Runtime Library。然而,它还没有准备好使用,开发人员似乎已经放弃了它。 主页链接位于此处。
在这里发布这个答案,希望它对人们在将来的某个时候进行谷歌搜索有用。
Having spent a while searching for this myself, I came across this post introducing the in-progress Mingw32 Alternate C Runtime Library. However, it's not ready for use, and the developer appears to have abandoned it. Home page link here.
Posting this answer here in the hope that it'll come in useful to people googling at some point in future.
这并没有回答“如何避免与 MSVCRT.DLL 链接”的问题,但如果您来这里是为了了解“如何静态与 MinGW 链接”这一更一般的问题, em>“...:
与
gcc -static -static-libgcc -static-libstdc++
链接,您将不需要libgcc_s_dw2-1.dll
和libstdc++ -6.dll
This doesn't answer the question of "how to avoid linking with MSVCRT.DLL", but if you're here for a more general question of "How to link with MinGW statically"...:
Link with
gcc -static -static-libgcc -static-libstdc++
and you won't needlibgcc_s_dw2-1.dll
andlibstdc++-6.dll