The C++ libraries are linked by default when building an executable program, but not when building a shared library (.so using –G). When building a shared library with –G, all needed libraries must be listed explicitly. The -zdefs option will cause the linker to complain if a needed library is omitted, and is the default when building an executable program. In default -compat=5 mode, the following libraries are linked by default by the CC driver:
In -std=c++03, -std=c++11, and -std=c++14 modes, the following libraries are linked by default by the CC driver:
-lstdc++ -lgcc_s -lCrunG3 -lm -lc
On Linux, libCrunG3, when used, is linked statically by default. You can get the same behaviour by using:
-lstdc++ -lgcc_s -Bstatic -lCrunG3 -Bdynamic -lm -lc
See –library=l[,l...] for more information.