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

Document Information

Preface

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

12.  Using The C++ Standard Library

13.  Using the Classic iostream Library

14.  Using the Complex Arithmetic Library

15.  Building Libraries

15.1 Understanding Libraries

15.2 Building Static (Archive) Libraries

15.3 Building Dynamic (Shared) Libraries

15.4 Building Shared Libraries That Contain Exceptions

15.5 Building Libraries for Private Use

15.6 Building Libraries for Public Use

15.7 Building a Library That Has a C API

15.8 Using dlopen to Access a C++ Library From a C Program

Part IV Appendixes

A.  C++ Compiler Options

B.  Pragmas

Glossary

Index

15.7 Building a Library That Has a C API

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++ run-time support and you are linking with cc, then you must also link your application with either libC (compatibility mode) or libCrun (standard mode) when you use the C-interface library. (If the C-interface library does not need C++ run-time support, then you do not have to link with libC or 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.

When providing a shared C-interface library you must create a dependency on libC or libCrun at the time that you build the library. When the shared library has the correct dependency, you do not need to add -lC or -lCrun to the command line when you use 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: