A C wrapper is nothing but a set of functions, one for each method of the class, compiled (in C++) together with the class. The function that calls the constructor method must return a pointer to the class, and every other function must include the class pointer as one of its arguments.
The header file describing the class and its wrapper should be shared by the class source file and the calling program. The C++ compiler defines (built in) the switch __cplusplus, and the header file can ifdef that switch to present different views to each compiler. The C++ compiler should see the prototypes bracketed by keyword "extern", like this:
extern "C" { prototype( ); }
but the C compiler should see the prototypes without the keyword "extern" or the curly braces. The C++ compiler should see the class definition as well as the wrapper prototypes, but the C compiler should see only the wrapper prototypes, not the class definition.
This directory contains five files:
It's easy once you know how!