Calling a C++ function from a C program

南楼画角 提交于 2020-01-14 04:42:08

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/499293/calling-a-c-function-from-a-c-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!