Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C++ namespaces in objective C

Tags:

objective-c

I am working on a project that requires a third party library implemented in C++. I have successfully added library to my xcode project, but the problem is that the classes in library contains namespaces and when I try to access methods via namespaces, the XCode generates an error that: "utils undeclared". "utils" is the namespace I am trying to use.

My question is that is there a way to use C++ namespaces in ObjectiveC?

The code I am using to call the method is: utils::method();

I have tried renaming my ObjectiveC ".m" file to ".mm" file, but the problem remains the same.

like image 517
Mustafa Saify Avatar asked Sep 17 '25 06:09

Mustafa Saify


1 Answers

We are using C++ libraries in Objective-C and have no problem using C++ namespaces. As Mustafa has indicated, you need to change the Objective-C file extension to .mm to get XCode to recognize the file as Objective-C++. Then you just need to #include (not #import) the C++ headers containing the C++ namespace declarations - this is as you would normally do for 'normal' C++.

like image 85
Andrew Wyatt Avatar answered Sep 20 '25 01:09

Andrew Wyatt