including C/C++ headers in Xcode 4

Eric picture Eric · Jan 16, 2012 · Viewed 8.6k times · Source

I've been using a C++ library without problems on projects built with Xcode 3, but I'm now getting build problems on projects built with Xcode 4.

Drop the library into the Xcode 4 project and it builds fine, but as soon as I #include it, I get a "Lexical or Preprocessor Issue" error, more specifically " 'string' file not found, on line 4 of its main header file.

On closer inspection, the error specifies that 'string' file not found in ~/my project's directory/include/mainheader.h

I've tried the solutions listed here, but none worked.

So it thinks that header file is in my project directory, but it's obviously a C/C++ header… How can I tell Xcode to look for these C/C++ headers?

Answer

Eric picture Eric · Jan 17, 2012

The problematic #include was at the top of my ViewController.mm, which I had already turned into Objective-C++ by giving it .mm as its extension. But ViewController.mm gets eventually imported by AppDelegate.m, which is Objective-C by default – and I had forgotten to make it Objective-C++, hence the problem.

So renaming AppDelegate.m to AppDelegate.mm solved the problem.