#include <string> 文件未在 iOS 中的 C++ 文件中找到
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10405153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
#include <string> file not found in iOS in C++ file
提问by daven11
I have a objective c/c++ project under iOS, moving it from OS/X and I get a 'file not found' error on
我在 iOS 下有一个客观的 c/c++ 项目,将它从 OS/X 移动,但出现“找不到文件”错误
#include <string>
It's a clean project, and I've just added the files from the old project. Are the STL includes set up in XCode? A find produces a number of possibilities e.g.
这是一个干净的项目,我刚刚添加了旧项目中的文件。STL 包含是否在 XCode 中设置?find 产生多种可能性,例如
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/usr/include/c++/4.2.1/debug/
but adding this to the search path just threw up more errors. Any suggestions? (apart from don't use string - it's in house code I'm porting)
但是将它添加到搜索路径只会引发更多错误。有什么建议?(除了不要使用字符串 - 这是我正在移植的内部代码)
xcode 4.2.1, ios5.0 running on OS/X 10.7.3 and it's in a .cpp file, the code works fine on OS/X
xcode 4.2.1, ios5.0 在 OS/X 10.7.3 上运行,它在一个 .cpp 文件中,代码在 OS/X 上运行良好
回答by Macmade
Are you really sure <string>
is included only from a .cpp file?
你真的确定<string>
只包含在 .cpp 文件中吗?
I just tested on a fresh project, by adding a .cpp file and including <string>
, and it works, just as expected (same Xcode version, same SDK version).
我刚刚通过添加一个 .cpp 文件并包含<string>
.
But if I include <string>
in a .m file, then of course I got a ?file not found? compiler error.
但是如果我包含<string>
在一个 .m 文件中,那么我当然会得到一个 ?file not found?编译器错误。
So double-check this, as the error may come from here.
所以仔细检查一下,因为错误可能来自这里。
Do you include <string>
from a .cpp file only, or from a .h file, intended to be used by a .cpp implementation?
Then maybe it's also included by a .m file, hence the error.
您是<string>
仅从 .cpp 文件中包含,还是从 .h 文件中包含,旨在供 .cpp 实现使用?
然后也许它也包含在 .m 文件中,因此出现错误。
Also check your precompiled headers, if any, to see if you include some C++ stuff there...
还要检查你的预编译头文件,如果有的话,看看你是否在那里包含了一些 C++ 的东西......
Also remember, in that later case, that you can rely on the __cplusplus
macro, when needed.
还要记住,在后一种情况下,您可以__cplusplus
在需要时依赖宏。
回答by Halsafar
If you include a header in an ObjC file and it includes <string>
then you hit errors like this. For all .m files XCode uses a C compiler (clang or llvm-gcc). For all .mm files it will use (clang++ or llvm-g++).
如果您在 ObjC 文件中包含一个标头并且它包含,<string>
那么您会遇到这样的错误。对于所有 .m 文件,XCode 使用 C 编译器(clang 或 llvm-gcc)。对于所有 .mm 文件,它将使用(clang++ 或 llvm-g++)。
I suggest going through and renaming all your .m files to .mm. Including main.m to main.mm.
我建议仔细检查并将所有 .m 文件重命名为 .mm。包括 main.m 到 main.mm。