Interfacing to C++ (GNAT User’s Guide for Native Platforms)

#### 3.11.3.1 Interfacing to C++ ¶

GNAT supports interfacing with the G++ compiler (or any C++ compiler generating code that is compatible with the G++ Application Binary Interface —see ‘`http://itanium-cxx-abi.github.io/cxx-abi/abi.html`’).

You can do interfacing at three levels: simple data, subprograms, and classes. In the first two cases, GNAT offers a specific `Convention C_Plus_Plus` (or `CPP`) that behaves exactly like `Convention C`. Usually, C++ mangles the names of subprograms. To generate proper mangled names automatically, see Generating Ada Bindings for C and C++ headers). You can also address this problem addressed manually in two ways:

- by modifying the C++ code in order to force a C convention using the `extern "C"` syntax.
- by figuring out the mangled name (using e.g. `nm` or by looking at the assembly code generated by the C++ compiler) and using it as the `Link_Name` argument of the pragma `Import`.

You can achieve interfacing at the class level by using the GNAT specific pragmas such as `CPP_Constructor`. See the GNAT_Reference_Manual for additional information.