Old said:
You have to write a plain-C function in the
cpp file. ...
I would say, more precisely, that you have to define a C++ function
whose type has extern "C" language linkage. I don't like to call it a
"C" function, even though "C" language linkage makes it callable from C.
That's because the body of the function will be compiled according to
the rules of C++, and can use any C++ feature you want it to use (which
is precisely what makes it useful for this purpose).
Even the declaration of the function in C++ code will be handled
according to the rules of C++, not the rules of C, which could cause
problems if you're not careful. Obviously the declaration of the
interface function cannot use any type that cannot be declared in C.
However, it's also a potential problem that a syntactically valid C
function declaration could be an invalid C++ function declaration, or
have a different meaning in in C++. The most important of the
differences that could cause problems in the declaration are the ones
involving the scope and name space of identifiers (not be confused with
C++ namespaces, which are a very different concept).