If you want to create a library written in C ++, but this can be used with a C program, you must create a C API (application program interface). To do this, make all exported extern "C" functions. Please note that this can only be done for global functions and not for member functions.
If the C-interface library requires C ++ runtime support, and you are linking to cc, then you should also link your application with libC (compatibility mode) or libCrun (standard mode) when you use the C-interface library. (If the C interface library does not require C ++ runtime support, then you do not need to contact libC or libCrun.) The binding steps are different for archived and shared libraries.
When providing the C-interface archive library, you must provide instructions for using the library.
If the C-interface library was built with CC in standard mode (default), add -lCrun at the cc command line when using the C-interface library. If the C-interface library was built with CC in mode (-compat) compatibility, add -lC to the cc command line when using the C-Interface Library. By providing a common C-interface library, you must create a dependency on libC or libCrun at the time the library is created. 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 create the C-interface library in compatibility mode (-compat), add -lC to the CC command line when building the library. If you are building the C-interface library in standard mode (default), add -lCrun at the CC command line when creating the library. If you want to remove any dependency on the runtime of C ++ libraries, you must apply the following encoding rules in your library sources:
Do not use any new or delete form unless you provide your own appropriate versions. Do not use exceptions. Do not use information runtime type (RTTI).