Ian L
Ian L

Reputation: 5591

Integrating c++ alongside objective-c in iOS project

I've been tasked with adding some c++ code into an iOS project.

The c++ code comes in the form of several libs (.a), and header files with the extension .hpp

I have added these files into the XCode iOS project, and added the paths to the library and header search paths in the project settings, but I am getting compiler errors.

For example, one of the .hpp files contains:

`#include <string>`

and the error I am getting is "String: No such file or directory"

In the same hpp file there is a namespace declaration:

`namespace FooBar`

and there is an error on this line is "expected '=', ',', ';', 'asm' or 'attribute' before 'FooBar'"

I came straight into iOS programming so my experience has been primarily with objective-c. Can anyone offer any advice in terms of the project settings, search paths etc in order to get the c++ working alongside the obj-c?

Thanks in advance!

Upvotes: 3

Views: 2017

Answers (1)

tadman
tadman

Reputation: 211580

It could be that the Objective-C file that's including this header isn't in Objective-C++ mode. Usually you fix this by making your implementation a .mm file instead of .m since the latter is pure Objective-C.

Upvotes: 4

Related Questions