强制将头文件编译为Xcode中的C ++ [英] Force Header Files to Compile as C++ in Xcode

查看:54
本文介绍了强制将头文件编译为Xcode中的C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xcode 7.0中有一个用于iOS的Xcode项目,其中包含Objective-C,C ++和C代码.Xcode尝试将扩展名为.h(不是.hpp)的C ++头文件编译为C头文件,这会产生错误.

I have an Xcode project for iOS in Xcode 7.0 that contains Objective-C, C++, and C code. Xcode tries to compile the C++ header files with the extension .h (not .hpp) as C header files which generates errors.

我该如何解决?应该有一个设置,用于将哪些文件编译为哪种语言.

How do I fix this? There should be a setting for which files should be compiled as which language.

推荐答案

个别不编译头文件.包含它们的已编译源文件.如果将它们包括在.c中,则它们将像C一样编译,如果像.m这样的Objective-c,如果像.cpp这样的C ++,如果像.mm这样的Objective-C ++,就可以编译.

Individually header files doesn't compiled. Compiled source files where they included. If you include them in .c they will be compiled like C, if in .m - like Objective-c, if in .cpp - like C++, if in .mm - like Objective-C++.

.h或.hpp的命名方式无关紧要.

It doesn't matter how you name them .h or .hpp.

如果h文件中有部分C ++代码,则应将其放入

If you have some portion of C++ code in h-file- you should put it in

#ifdef __cplusplus
#endif

如果h文件中有部分Objective-C代码,则应将其放入

If you have some portion of Objective-C code in h-file you should put it in

#ifdef __OBJC__
#endif

这将使该语句中的代码对其他语言不可见.

This will make code inside this statement invisible for other languages.

您可以在Xcode生成的pch文件中找到此语句.

You can find this statement in Xcode's generated pch-file.

这篇关于强制将头文件编译为Xcode中的C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆