olipinski
olipinski

Reputation: 103

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

Is it possible to compile c++ without any lib? Because when i was trying to compile 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".

Upvotes: 1

Views: 575

Answers (3)

Andrejs Cainikovs
Andrejs Cainikovs

Reputation: 28434

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.

Upvotes: 4

Sergei Nikulov
Sergei Nikulov

Reputation: 5110

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.

Upvotes: 2

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385144

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.

Upvotes: 2

Related Questions