Force Header Files to Compile as C++ in Xcode

我的未来我决定 提交于 2021-02-05 08:55:10

问题


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.


回答1:


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++.

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

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

#ifdef __cplusplus
#endif

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.

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



来源:https://stackoverflow.com/questions/32827389/force-header-files-to-compile-as-c-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!