#include编译错误在可可应用程序中

发布于 2024-12-06 11:38:20 字数 454 浏览 0 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开浅夏 2024-12-13 11:38:20

你的源文件的扩展名是什么?如果是“.m”,尝试将其更改为obj-cpp“.mm”,以便Xcode推断出正确的语言。
或者只是将特定于 c++ 的标头放入“#ifdef __cplusplus”块中

更新

项目中编译的每种语言都必须存在防护,因为此特定包含位于 pch 中。 IOW,如果都是 c++ 和/或 objc++ 就不会出现错误。显然,至少有一个文件不能识别C++(例如C 或ObjC 源代码也在目标中编译)。因此,你只需像这样保护它:

// 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

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:

// 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
入怼 2024-12-13 11:38:20

string is a C++ header (for std::string). If you are looking for stuff like strcpy you need to include string.h

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文