简体   繁体   English

在iOS项目中添加C ++库无法正确编译

[英]Adding a C++ library in iOS project won't compile properly

In my iOS project I need to use a C++ library consisting in some header (.h) files and a .a library file (I don't have any actual source code). 在我的iOS项目中,我需要使用C ++库,其中包含一些头文件(.h)和.a库文件(我没有任何实际的源代码)。

In my Obj-c code I imported the .h header that I need, however Xcode doesn't seem to understand it has to interpret the header as c++, in fact it returns an endless list of issues including "not found" errors on inclusions like theese: 在我的Obj-c代码中,我导入了所需的.h标头,但是Xcode似乎不了解它必须将标头解释为c ++,实际上,它返回了无尽的问题列表,包括包含项中的“未找到”错误像这些人:

#include <string>
#include <vector>

and other c++ language-specific syntax. 和其他C ++语言特定的语法。 Unfortunately changing the .h extension to .hpp doesn't solve the issue, and neither setting the file type to "C++ Header" in the Xcode file inspector does. 不幸的是,将.h扩展名更改为.hpp并不能解决问题,在Xcode文件检查器中将文件类型设置为“ C ++ Header”也不能解决。

Any suggestion? 有什么建议吗? Is there any flag I need to set somewhere to manually indicate to use g++ on the library files? 我是否需要在任何地方设置标志以手动指示在库文件上使用g ++? Thanks. 谢谢。

您只能在Objective-C ++文件中导入C ++头文件,将objc文件扩展名更改为.mm

change your objectiveC-file extension from .m to .mm Clean the project then there you go 将您的ObjectiveC文件扩展名从.m更改为.mm清理项目,然后就可以了

happy coding 快乐编码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM