Skip Navigation Links | |
Exit Print View | |
Oracle Solaris Studio 12.3: C++ User's Guide Oracle Solaris Studio 12.3 Information Library |
3. Using the C++ Compiler Options
6. Creating and Using Templates
9. Improving Program Performance
10. Building Multithreaded Programs
12. Using the C++ Standard Library
13. Using the Classic iostream Library
14.2 Building Static (Archive) Libraries
14.3 Building Dynamic (Shared) Libraries
14.4 Building Shared Libraries That Contain Exceptions
14.5 Building Libraries for Private Use
14.6 Building Libraries for Public Use
If you want to build a library that is written in C++ but that can be used with a C program, you must create a C API (application programming interface). To do this, make all the exported functions extern "C". Note that this can be done only for global functions and not for member functions.
If a C-interface library needs C++ runtime support and you are linking with cc, then you must also link your application with libCrun (standard mode) when you use the C-interface library. (If the C-interface library does not need C++ runtime support, then you do not have to link with libCrun.) The steps for linking differ for archived and shared libraries.
When providing an archived C-interface library, you must provide instructions on how to use the library.
If the C-interface library was built with CC in standard mode (the default), add -lCrun to the cc command line when using the C-interface library.
If the C-interface library was built with CC in compatibility mode (-compat=4), add -lC to the cc command line when using the C-interface library.
When providing a shared C-interface library you must create a dependency on libCrun at the time that you build the library. When the shared library has the correct dependency, you do not need to add -lCrun to the command when you use the library.
If you are building the C-interface library in the default standard mode, add -lCrun to the CC command when you build the library.
If you want to remove any dependency on the C++ runtime libraries, you should enforce the following coding rules in your library sources:
Do not use any form of new or delete unless you provide your own corresponding versions.
Do not use exceptions.
Do not use runtime type information (RTTI).