[ACCEPTED]-How is the C++ standard library linked to my application?-mingw

Accepted answer
Score: 12

No, the standard libraries by default are 16 dynamically linked at runtime.

When running 15 the dynamic loader will look in a couple 14 of standard places for dynamic libraries 13 if it finds it loads and runs otherwise 12 the application quits.

On Unix Systems:
/usr/lib: look 11 for: libstdc++*

On Windows:
c:\windows\system32 10 look for: MSVCRT.DLL

There are also a couple 9 of Environment variables that can affect 8 the search path. Look at your platforms 7 man page for dlopen to see what they are. Everything 6 you need should be in the man pages for 5 dlopen on your platform.

Most systems have 4 these libs in the appropriate places and 3 will automatically be found.
The rest of 2 the STL will not introduces extra shared 1 lib dependencies.

Score: 7

In recent MinGW gcc/g++ versions (4.40) you 7 can link against a shared dll rather than 6 the default static library by using the 5 flag -shared-libstdc++.

The static versions 4 of the library are located in /mingw/lib/gcc/mingw32/[gcc 3 version]. The file name is libstdc++.a. This 2 will be linked in by default when compiling 1 a c++ app with MinGW.

Score: 3

The only basic run-time dependancy for MinGW 11 C++ programs is on MSVCRT.DLL. Other dependancies 10 will depend on what your program actually 9 does - for example, if it uses ODBC database 8 connectivity, it will depend on ODBC32.DLL 7 (and probably some other Windows DLLs). However, using 6 classes like std::string or std::vector 5 in a MinGW C++ program will not introduce 4 new dynamic library dependancies.

If you 3 are worried about dynamic library dependancies, check 2 out the tool "Dependency Walker" at 1 http://www.dependencywalker.com/

Score: 2

Most of it's all in the header files, because 2 it's so heavily templated. Very little 1 requires libstdc++.so (iostream, may be it, I think).

Score: 1

C and C++ runtime libraries are linked in 22 the same way as normal libraries, the main 21 difference is that they are usually automatically 20 compiled against and linked by the compiler 19 and linker with no need to specify them.

It 18 is incorrect however, to generalise that 17 you don't have to ship them with your app. In 16 most cases where you ship dynamically linked 15 binaries you will need to include them, for 14 example if you compile with MSVC++, you 13 will link against whatever is installed 12 on your build machine, if you install the 11 dynamically linked binary on a fresh windows 10 install, you are likely to run into problems 9 unless you ensure the libraries are included 8 as part of the installpack (see documentation 7 about visual studio redistributables). The 6 same is true on Solaris machines (standard 5 libraries are upgraded as part of a patch 4 set). With Linux, it's more complicated, you 3 can't link statically due to the GPL, however 2 the libraries are usually installed via 1 distro packages.

More Related questions