Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top