简体   繁体   中英

ObjC++ calling static library written in C

I have an iOS project utilizing ffmpeg (which is a pure C library) and OpenCV.

Since I use the C++ interface of OpenCV, I write objective-c++ which is a .mm file. But the file is not OK with ffmpeg, and Xcode complains about undefined symbol on linking stage.

I also use ffmpeg in another .m file and it is OK. So I am sure the problem is with .mm and static library written in C.

When using .mm you get c++ name mangling (as opposed to c name mangling).

Fix by adding an "extern c" wrapper to your c-function declaration (not needed for the definition)

extern "C" {

int somecallback(int param);

}

EDIT: Usually c-header files has this wrapping arranged already, look for something similar to

#if defined  __cplusplus
extern "C" {
#endif

in the .h file, if not found then put the #include inside ypur own wrapper.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM