Can I link MSVCRT statically with mingw?

℡╲_俬逩灬. 提交于 2019-11-29 14:55:10

问题


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?


回答1:


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




回答2:


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.




回答3:


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 need libgcc_s_dw2-1.dll and libstdc++-6.dll



来源:https://stackoverflow.com/questions/3943412/can-i-link-msvcrt-statically-with-mingw

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