views:

126

answers:

1

Hello,

How can I call a C++ function from a C program, is it possible?, and if it is how can I do it?. Thank you.

+6  A: 

If you are trying to call a C++ function from C, then you are probably running into name mangling issues. The compiler does this in order to support function overloading and other features of C++.

You can use extern "C" to inform the C++ compiler that the function CMACInit() will be called from C code:

extern "C" CMACInit() { ... }

When declared in this way, the C++ compiler will not mangle the name and will set everything up so the function can be called from C code.

Greg Hewgill