4

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?

Community
  • 1
  • 1
Eric
  • 12,878
  • 13
  • 78
  • 119

2 Answers2

12

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.

Eric
  • 12,878
  • 13
  • 78
  • 119
0

I think #include is a c++ class template..so you need to used using namespace std in your header file and also rename your source file .m format to .mm format.

it works for me :) try this...

Saif
  • 1,867
  • 1
  • 15
  • 39
  • 1
    I'm not familiar with xCode and OSX/iOS development, but this statement - *#include is a c++ class template* - is definitely not correct. – Andrejs Cainikovs Jan 16 '12 at 18:37
  • The C++ Standard Template Library (STL) contains a string class that is used in several computer science classes. Check this :: http://www.bgsu.edu/departments/compsci/docs/string.html http://www.cplusplus.com/reference/string/string/string/ http://www.cplusplus.com/reference/string/string/ – Saif Jan 16 '12 at 18:39
  • Thanks, but none of your links shows the explanation. This page has it at the very end: http://www.cplusplus.com/doc/tutorial/templates/ – Andrejs Cainikovs Jan 16 '12 at 18:40
  • 1
    Putting `using namespace ANYTHING;` in a header is not a good idea. There is no point having namespaces in that case. – dreamlax Jan 16 '12 at 19:06
  • @saif Your solution (renaming the source file) is probably correct, but the answer is a bit confusing. `std::string` is not a template, but it is a class. I think you might mean "class declaration". `#include` is a way to read other files, regardless of their contents. – Per Johansson Jan 17 '12 at 08:04