JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.3: C++ User's Guide     Oracle Solaris Studio 12.3 Information Library
search filter icon
search icon

Document Information


Part I C++ Compiler

1.  The C++ Compiler

2.  Using the C++ Compiler

3.  Using the C++ Compiler Options

Part II Writing C++ Programs

4.  Language Extensions

5.  Program Organization

6.  Creating and Using Templates

7.  Compiling Templates

8.  Exception Handling

9.  Improving Program Performance

10.  Building Multithreaded Programs

Part III Libraries

11.  Using Libraries

11.1 C Libraries

11.2 Libraries Provided With the C++ Compiler

11.2.1 C++ Library Descriptions

11.2.2 Accessing the C++ Library Man Pages

11.2.3 Default C++ Libraries

11.3 Related Library Options

11.4 Using Class Libraries

11.4.1 iostream Library Note About Classic iostreams and Legacy RogueWave Tools

11.4.2 Linking C++ Libraries

11.5 Statically Linking Standard Libraries

11.6 Using Shared Libraries

11.7 Replacing the C++ Standard Library

11.7.1 What Can Be Replaced

11.7.2 What Cannot Be Replaced

11.7.3 Installing the Replacement Library

11.7.4 Using the Replacement Library

11.7.5 Standard Header Implementation Replacing Standard C++ Headers Replacing Standard C Headers

12.  Using the C++ Standard Library

13.  Using the Classic iostream Library

14.  Building Libraries

Part IV Appendixes

A.  C++ Compiler Options

B.  Pragmas



11.5 Statically Linking Standard Libraries

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 11.2.3 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 mode (the default 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.

Note - Linking the libCrun and libCstd statically is not recommended. The dynamic versions in /usr/lib are built to work with the version of Oracle Solaris where they are installed.

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 A.2.147 -xnolib for more information. See Linker and Libraries Guide for more information about ld.

Note - Static versions of Oracle Solaris libraries in /lib and /usr/lib are no longer available. For example, this attempt to link libc statically will fail:

      CC -xnolib -lCrun -lCstd -Bstatic -lc