When I usually use code (include headers) from 3rd party (non-standard) C++ libraries, a pre-built binary file is linked to (or included in) the target executable that represents my application, but what happens with C++ standard library?, as far as I have seen I don't have to ship a library with an application that uses code only from the C++ standard library, thus is the code statically linked and included in the executable?
Most of it's all in the header files, because it's so heavily templated. Very little requires libstdc++.so
(iostream
, may be it, I think).
No, the standard libraries by default are dynamically linked at runtime.
When running the dynamic loader will look in a couple of standard places for dynamic libraries if it finds it loads and runs otherwise the application quits.
On Unix Systems:
/usr/lib: look for: libstdc++*
On Windows:
c:\windows\system32 look for: MSVCRT.DLL
There are also a couple of Environment variables that can affect the search path. Look at your platforms man page for dlopen to see what they are. Everything you need should be in the man pages for dlopen on your platform.
Most systems have these libs in the appropriate places and will automatically be found.
The rest of the STL will not introduces extra shared lib dependencies.
The only basic run-time dependancy for MinGW C++ programs is on MSVCRT.DLL. Other dependancies will depend on what your program actually does - for example, if it uses ODBC database connectivity, it will depend on ODBC32.DLL (and probably some other Windows DLLs). However, using classes like std::string or std::vector in a MinGW C++ program will not introduce new dynamic library dependancies.
If you are worried about dynamic library dependancies, check out the tool "Dependency Walker" at http://www.dependencywalker.com/
In recent MinGW gcc/g++ versions (4.40) you can link against a shared dll rather than the default static library by using the flag -shared-libstdc++.
The static versions of the library are located in /mingw/lib/gcc/mingw32/[gcc version]. The file name is libstdc++.a. This will be linked in by default when compiling a c++ app with MinGW.
C and C++ runtime libraries are linked in the same way as normal libraries, the main difference is that they are usually automatically compiled against and linked by the compiler and linker with no need to specify them.
It is incorrect however, to generalise that you don't have to ship them with your app. In most cases where you ship dynamically linked binaries you will need to include them, for example if you compile with MSVC++, you will link against whatever is installed on your build machine, if you install the dynamically linked binary on a fresh windows install, you are likely to run into problems unless you ensure the libraries are included as part of the installpack (see documentation about visual studio redistributables). The same is true on Solaris machines (standard libraries are upgraded as part of a patch set). With Linux, it's more complicated, you can't link statically due to the GPL, however the libraries are usually installed via distro packages.