user2877212
user2877212

Reputation:

Force Header Files to Compile as C++ in Xcode

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.

Upvotes: 2

Views: 4692

Answers (1)

Cy-4AH
Cy-4AH

Reputation: 4586

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.

Upvotes: 4

Related Questions