Compile C # include <string> errors in Cocoa application
I am trying to compile a Cocoa application in xcode 4.0 and I am getting this error ...
fatal error: 'string' file not found ... when trying to compile a .pch file on this line:
#include <string> I have another xcode project that does the same thing but does not get an error. I looked at the build settings for some different ones, but I can not find them. The only difference is that the project that compiles OK started as a command-line project, not a Cocoa project, but the build option is the same.
Target OS - Mac OS X 10.6
An error occurred while compiling the precompiled header and did not fall into any of the other files. The only structure that has a compilation version is the Foundation.framework framework and non-compiling.
Why doesn't he find it in one project and not in another? Any tips?
What is the extension of your source files? If it is ".m", try changing it to obj-cpp ".mm" so that Xcode will output the correct language. Or just put C ++ specific headers inside the "#ifdef __cplusplus" block
Update
A protector must exist for every language compiled in the project, because this particular include is in pch. IOW, if all C ++ and / or objC ++ had no errors. Obviously, there is at least one file that C ++ does not recognize (for example, C or ObjC sources are also compiled to the target). Therefore, you simply protect it like this:
// MONPrefix.pch #ifdef __cplusplus #include <string> #endif // same for objc, so your C and C++ sources compile with no error: #ifdef __OBJC__ #include <Foundation/Foundation.h> #endif string - C ++ header (for std :: string). If you are looking for things like strcpy you need to include string.h