The CC driver links in shared versions of several libraries by default, including libc and libm, by passing a -llib option for each of the default libraries to the linker. (See Default C++ Libraries for the list of default libraries.)
If you want any of these default libraries to be linked statically, you can use the -library option along with the –staticlib option. For example:
example% CC test.c -staticlib=Crun
In this example, the -library option is not explicitly included in the command. In this case, the -library option is not necessary because the default setting for -library is Cstd,Crun in standard -compat=5 mode.
Alternately, you can use the -xnolib compiler option. With the -xnolib option, the driver does not pass any -l options to ld; you must pass these options yourself. The following example shows how you would link statically with libCrun, and dynamically with libm, and libc:
example% CC test.c -xnolib -lCstd -Bstatic -lCrun -Bdynamic -lm -lc
The order of the -l options is important. The –lCstd, –lCrun, and -lm options appear before -lc.
Some CC options link to other libraries. These library links are also suppressed by -xnolib. For example, using the -mt option causes the CC driver to pass -lthread to ld. However, if you use both–mt and –xnolib, the CC driver does not pass-lthread to ld. See –xnolib for more information. See Oracle Solaris 11.3 Linkers and Libraries Guide for more information about ld.
CC hello.cc -xnolib -lCrun -lCstd -Bstatic -lc