从C程序调用C ++函数 [英] Calling a C++ function from a C program
本文介绍了从C程序调用C ++函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从C程序调用C ++函数,这可能吗?如果可以,怎么办?谢谢.
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.
推荐答案
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++.
您可以使用extern "C"
通知C ++编译器将从C代码中调用函数CMACInit()
:
You can use extern "C"
to inform the C++ compiler that the function CMACInit()
will be called from C code:
extern "C" CMACInit() { ... }
以这种方式声明时,C ++编译器不会更改名称,而是会进行所有设置,以便可以从C代码中调用该函数.
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.
这篇关于从C程序调用C ++函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文