Xcode 项目 #include <cmath>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10567843/
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
Xcode Project #include <cmath>
提问by casillic
I'm trying to use code that already works in another standalone project without problems.
我正在尝试使用已经在另一个独立项目中正常工作的代码而没有问题。
When I bring this code into my other final project, it indicate that 'cmath' file not found.
当我将此代码带入我的另一个最终项目时,它表明未找到“cmath”文件。
The file with the #include is in an .hpp file (it just defines some structs for opengl stuff), so there is not a corresponding .mm file. (This is C++ code and I'm mainly an objective-c user so not sure of all the c++ stuff) But this is for opengl stuff and works fine we not in this project.
带有 #include 的文件位于 .hpp 文件中(它只是为 opengl 定义了一些结构),因此没有相应的 .mm 文件。(这是 C++ 代码,我主要是一个 Objective-C 用户,所以不确定所有的 C++ 东西)但这是针对 opengl 的东西,并且在我们不在这个项目中工作得很好。
I've tried everything to make this work.
我已经尝试了一切来完成这项工作。
The final project with the problem has other code that uses #include without problems. It is almost like something is causing xcode not to recognize the path the header anymore. I've checked its file type it is "Default C++ header"
有问题的最终项目有其他代码使用#include 没有问题。这几乎就像是什么导致 xcode 不再识别标题的路径。我检查了它的文件类型,它是“默认 C++ 标头”
In the final project I'm using Zxing and also using CorePlots. Not sure if they are causing any problems. Also some file are using #include not sure if that could conflict with the #incude or not. (But again the other files with #include are working fine.
在最终项目中,我使用 Zxing 和 CorePlots。不确定它们是否造成任何问题。还有一些文件正在使用 #include 不确定是否会与 #incude 冲突。(但同样带有 #include 的其他文件工作正常。
Any help will be greatly appreciated...
任何帮助将不胜感激...
回答by buildsucceeded
Alternately to Jon Reid's good advice you can pick "Compile as Objective-C++" in the Build Settings. (Search for "Compile sources" in the Build Settings window.) This is a little bit wild-west but is a quick way to see if the problem is in fact your C++ source compiling as C or Objective-C
除了 Jon Reid 的好建议,您还可以在 Build Settings 中选择“Compile as Objective-C++”。(在“构建设置”窗口中搜索“编译源”。)这有点狂野,但可以快速查看问题是否实际上是您的 C++ 源编译为 C 或 Objective-C
回答by Jon Reid
Your header file doesn't exist by itself; something must import it. Rename the importing files, changing their file types from .m to .mm.
您的头文件本身并不存在;有些东西必须导入它。重命名导入文件,将其文件类型从 .m 更改为 .mm。
For example, let's say your header that includes <cmath> is named foo.h. And that this in turn is used by a bar
module, composed of bar.h and bar.m. So foo.h is imported in either bar.h or bar.m.
例如,假设包含 <cmath> 的头文件名为 foo.h。这反过来又被一个bar
由 bar.h 和 bar.m 组成的模块使用。所以 foo.h 被导入到 bar.h 或 bar.m 中。
Rename bar.m to bar.mm so that it uses C++. Do the same for all .m files that depend on foo.h.
将 bar.m 重命名为 bar.mm,以便它使用 C++。对所有依赖于 foo.h 的 .m 文件执行相同的操作。