[英]ObjC++ calling static library written in C
I have an iOS project utilizing ffmpeg (which is a pure C library) and OpenCV. 我有一个使用ffmpeg(是纯C库)和OpenCV的iOS项目。
Since I use the C++ interface of OpenCV, I write objective-c++ which is a .mm
file. 由于我使用OpenCV的C ++接口,因此我编写了.mm
文件的Objective-c ++。 But the file is not OK with ffmpeg, and Xcode complains about undefined symbol
on linking stage. 但是使用ffmpeg不能正常运行该文件,并且Xcode在链接阶段抱怨undefined symbol
。
I also use ffmpeg in another .m
file and it is OK. 我还在另一个.m
文件中使用ffmpeg,这没关系。 So I am sure the problem is with .mm
and static library written in C. 所以我敢肯定问题出在.mm
和用C编写的静态库。
When using .mm you get c++ name mangling (as opposed to c name mangling). 使用.mm时,您会得到c ++名称修饰(与c名称修饰相反)。
Fix by adding an "extern c" wrapper to your c-function declaration (not needed for the definition) 通过在您的c函数声明中添加“外部c”包装器来解决(该定义不需要)
extern "C" {
int somecallback(int param);
}
EDIT: Usually c-header files has this wrapping arranged already, look for something similar to 编辑:通常c头文件已经安排了这种包装,寻找类似于
#if defined __cplusplus
extern "C" {
#endif
in the .h file, if not found then put the #include inside ypur own wrapper. 在.h文件中,如果找不到,则将#include放入ypur自己的包装器中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.