问题描述
我在项目中添加了一个框架,该框架用于获取我需要实现c ++代码的回调,为此我添加了来自.cpp的.mm的c ++类
I have added one framework in my project, where to get the callbacks of framework I need to implement c++ code,for which I have added c++ classes which are .mm from .cpp
我还遇到了StackOverflow的几篇文章,发现我要么必须使用C ++,要么必须使用Objective C源类型(这是少数成员的建议).
I also came across few posts of StackOverflow, where I found either I have to go for C++ or Objective C source type(as suggestion of few members).
我正在寻找将C ++代码与Objective C类一起编译的方法,但我却发现#include <cstdlib> and #include <string>
的文件未找到错误(编译时)
I am looking to compile c++ code along with Objective C classes,but I am getting file not found error (compile time) for #include <cstdlib> and #include <string>
请让我知道有人在解决它,或者遇到了相同的问题.
Please let me know any one worked around it.or faced same Issue.
在此先感谢!!!
推荐答案
我认为问题是,您在其中添加了C ++的.h文件包含在其他.m文件中,而不仅仅是.mm.有几种方法可以解决此问题:
I think problem is that your's .h-file, where you have added C++ includes is included in other .m-files, not just in .mm.There is several ways to solve this problem:
- 仅在.mm文件中使用C ++. (请勿在.h中使用它们)
- 更改所有文件,这些文件会将您的标头导入到.mm
-
将它们包括在
- Use C++ includes only in .mm files. (don't use them in .h)
- Change all files, that import yours header to .mm
Include them in
#ifdef __cplusplus
#endif
块.还将此块用于提及C ++类的方法.例如:
block. Also use this block for methods where C++ classes mentioned.For example:
#ifdef __cplusplus
#include <string>
using namespace std;
#endif
@interface SomeClass
#ifdef __cplusplus
- (void) setName:(const string&) name;
#endif
@end
还有一种方法可以通过使用扩展名和类别来避免#ifdef #endif
阻塞:
Also there is way to avoid #ifdef #endif
block by using extensions and categories:
- 仅在扩展中声明C ++的实例变量.
- 为使用C ++类型的方法和属性创建带有附加.h文件的类别.
这篇关于编译#include< cstdlib>在Xcode-编译期间错误:找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!