开发者

Is it possible to compile c++ without any lib?

开发者 https://www.devze.com 2023-04-13 04:32 出处:网络
Is it possible to compile c++ without any lib? Because when i was trying to c开发者_如何学Goompile my program with Mingw and cygwinafter the .exe file was made i couldn\'t run it and it said there is

Is it possible to compile c++ without any lib? Because when i was trying to c开发者_如何学Goompile my program with Mingw and cygwin after the .exe file was made i couldn't run it and it said there is a missing library. For cygwin it was "cygwin1.dll".


Binaries that are build with Cygwin always has dependency on cygwin1.dll. Hovewer, if you want to avoid this, use linker option -mno-cygwin. This way you'll make sure that there will be no dependency on cygwin runtime library that you need to ship with your app.

MinGW has some local dependencies too. In particular, libgcc_s_dw2-1.dll(depends on what unwinding type is used in your toolchain) and mingwm10.dll. To get rid of them, use -static-libgcc and -mthreads options for your linker. Please note that C++ exceptions depends on this option.

Small note, however. Your question - "Is it possible to compile c++ without any lib?" is incorrect, since there are always some dependencies on libs (unless you are building binary for barebone hardware w/o OS), for example user32.dll for Windows. Sure, nor Cygwin nor MinGW is suitable for that.


It's not just a library; it's the runtime that you need to run applications compiled with Cygwin.

If you're really using MinGW then you can avoid Cygwin entirely with -mno-cygwin but even then you're going to need the MinGW runtime and, probably, the C++ Standard Library. However, these can generally be linked statically so that you don't need to ship any dependencies.


General answer - no. The runtime support required by C++ code in general, to enable features like RTTI and exception handling. So anyway you'll must link executable with libstdc++, either dynamically or statically.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号