Can I link MSVCRT statically with mingw?

2019-02-09 17:39发布

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?

3条回答
何必那么认真
2楼-- · 2019-02-09 18:05

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

查看更多
霸刀☆藐视天下
3楼-- · 2019-02-09 18:11

Link with gcc -static -static-libgcc -static-libstdc++ and you won't need libgcc_s_dw2-1.dll and libstdc++-6.dll

查看更多
淡お忘
4楼-- · 2019-02-09 18:26

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.

查看更多
登录 后发表回答