I have heared that C++ Standard Library is automatically linked to C++ programs. Is it possible to prevent this? (I'm using Visual C++ 2010 Express)
Not sure about MSVC++2010, but in GCC you add the -nostdlib
flag to the linker flags. This isn't really recommended unless you know what you're doing, since among those libraries are the runtime that makes sure things like static constructors and destructors get called, variables are initialized, and free space is cleared, in addition to calling main
. (One case where it's useful is in embedded systems with no OS.)
Is C++ Standard Library present on major OS(s) such as Windows, Mac OS X, Linux and Unix?
Yes. It's part of the toolchain.
why some programs redistribute the Microsoft C++ 2010 Redistributables?
Because Microsoft decided to implement part of the runtime as a shared library (a.k.a. DLL) instead of just statically linking all of it, or making the shared library a standard part of Windows. Also, it may include Windows-specific APIs that Microsoft added which aren't technically part of the C++ standard libraries.
Where C++ Standard Library is actually located on various Operating Systems?
Buried somewhere in your toolchain. In the case of GCC, you use the gcc-config -L
command:
$ gcc-config -L
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3:/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/32
$ ls /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3
32 hardenednopie.specs libgomp.la libstdc++.a
crtbegin.o hardenednopiessp.specs libgomp.so libstdc++.so
crtbeginP.o hardenednossp.specs libgomp.so.1 libstdc++.so.6
crtbeginS.o include libgomp.so.1.0.0 libstdc++.so.6.0.17
crtbeginT.o include-fixed libgomp.spec libsupc++.a
crtend.o libgcc.a libitm.a libsupc++.la
crtendS.o libgcc_eh.a libitm.la plugin
crtfastmath.o libgcc_s.so libitm.so vanilla.specs
crtprec32.o libgcc_s.so.1 libitm.so.1
crtprec64.o libgcov.a libitm.so.1.0.0
crtprec80.o libgomp.a libitm.spec
How it's possible to embed Required C++ Standard Library files into the application?
They're linked like any other library, so if you want to hard-wire them in, you use the static versions of these libraries. In Unix-type OSes, you just link to the .a
versions of the libraries instead of the .so
versions. I'm not sure DLLs have static versions, though...