#include编译错误在可可应用程序中
我正在尝试在 xcode 4.0 中编译 Cocoa 应用程序,但遇到此错误...
fatal error: 'string' file not found
...当尝试在这一行上编译为 .pch 文件时:
#include <string>
我有另一个 xcode 项目执行相同的操作,但不执行此操作得到错误。我已经搜索了一些不同的构建设置,但找不到。唯一的区别是编译成功的项目是作为命令行项目启动的,而不是 Cocoa 项目,但构建设置是相同的。
目标操作系统是 Mac OS X 10.6
编译预编译头时会发生错误,并且无法访问任何其他文件。编译版本唯一的框架是Foundation.framework,非编译版本也有。
为什么它在一个项目中找不到,而在另一个项目中却找不到?有什么建议吗?
I am trying to compile a Cocoa app in xcode 4.0 and I'm getting this error...
fatal error: 'string' file not found
...when trying to compile to .pch file on this line:
#include <string>
I have another xcode project that does the same thing, but does not get the error. I have scoured the build settings for some different, but I can't find one. The only difference is that the project that compiles OK was started as a command line project, not a Cocoa project, but the build setting are the same.
The target OS is Mac OS X 10.6
The error happens when compiling the precompiled header and doesn't get to any of the other files. The only framework that the compiling version has is Foundation.framework and the non-compiling one has it as well.
Why is it not finding in one project and not the other? Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的源文件的扩展名是什么?如果是“.m”,尝试将其更改为obj-cpp“.mm”,以便Xcode推断出正确的语言。
或者只是将特定于 c++ 的标头放入“#ifdef __cplusplus”块中
更新
项目中编译的每种语言都必须存在防护,因为此特定包含位于 pch 中。 IOW,如果都是 c++ 和/或 objc++ 就不会出现错误。显然,至少有一个文件不能识别C++(例如C 或ObjC 源代码也在目标中编译)。因此,你只需像这样保护它:
What is the extension of your source files? If it is ".m", try to change it to obj-cpp ".mm", so that Xcode will deduce correct language.
Or just put c++-specific headers inside "#ifdef __cplusplus" block
Update
The guard must exist for each language compiled in the project because this specific include is in the pch. IOW, if it were all c++ and/or objc++ there would be no error. Evidently, there is at least one file that does not recognize C++ (e.g. C or ObjC sources are also compiled in the target). Therefore, you simply guard it like so:
string
is a C++ header (for std::string). If you are looking for stuff likestrcpy
you need to includestring.h