Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to call c++ functions from objective-c code without .mm extension?

Is there any way to call c++ functions from objective-c code without .mm extension? For example maybe it is possible to create a C wrapper or anything else that can help in this situation? I know that it is possible assign type "objective-c++ source" for .m files but it is not what I want.

like image 433
Nik Avatar asked Nov 26 '25 13:11

Nik


1 Answers

Yes, I do this often. You will need a small amount of .mm glue code, but your intuition of using wrappers is correct. You may be interested in Wrapping C++ - Take 2.

There are good reasons to avoid excessive use of .mm files. They compile slower, run slower (particularly under ARC where they incur significant overhead), confuse gdb in my experience, and the mixing of ObjC and C++ classes is quite confusing and error-prone. Segmenting your ObjC and C++ with a thin layer between them is a good approach.

like image 86
Rob Napier Avatar answered Nov 29 '25 03:11

Rob Napier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!