1

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.

Eduardo
  • 19,928
  • 23
  • 65
  • 73

1 Answers1

6

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
  • 951,095
  • 183
  • 1,149
  • 1,285