Does it prohibited calling classic C function from Objective-C++ class method body?

匿名 (未验证) 提交于 2019-12-03 03:02:02

问题:

I have experienced some strange behavior of Objective-C++. I have an Objective-C++ class, and it calls a classic C function in a method body. But linker cannot find the C function.

I described the problem here: Xcode print symbol not found for my C function which used in Objective-C method body

I solved the problem by changing Objective-C++ class to Objective-C class, but the question is still remained. Does it prohibited calling C function in Objective-C++ class?

回答1:

You need to make sure that the C functions are declared

extern "C" 

in the appropriate .h file.

The common way of doing this is:

// // foo.h //  #ifndef __FOO_H__ #define __FOO_H__  #ifdef __cplusplus extern "C" { #endif  // ... your interface here - normal C function declarations etc ...  #ifdef __cplusplus } #endif  #endif 


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