4

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.

5
  • Regarding 3rd party libraries, you might be okay with using static libraries (rather than dylibs). Commented Jun 30, 2011 at 11:01
  • @Daniel why wouldn't they like 3rd party libraries? They're commonly used. Commented Jun 30, 2011 at 12:58
  • @Nektarios - I've heard of some submissions being rejected on the basis that a 3rd party library was used. It's hear say so I'm not sure it's true though Commented Jun 30, 2011 at 13:14
  • @Daniel as long as you're statically linking it's perfectly common and acceptable Commented Jun 30, 2011 at 14:06
  • Did you #include "…" the relevant header file? Commented Aug 25, 2012 at 23:17

1 Answer 1

6

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++.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, by the way, I am using XCode 3.2.6 - maybe you are using XCode 4 and it works differently in this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.