How to include C++ header file in objective-c++ header

Hello,

I am facing a problem in including a C++ header file like vector, set etc. in a objective-c++ header.

Lets suppose, I am having 2 files: abc.h abc.mm

Now, when I try to include the C++ header in abc.mm file, no build error is coming. But when I try to include the C++ header in abc.h file, it is throwing build error. Build error is: Header not found.

How to resolve this error? Any suggestion will be helpful.

Thanks Asheesh

Replies

Into what other file are you trying to include your abc.h ?

You can’t include it in an Obkective-C .m file, if it includes a C++ header.

(You might want to use the extension .hh to distinguish between obj-C and obj-C++ headers.)

  • I am including this header in only objective c++ file i.e., .mm file. But here the problem is not in importing the abc.h header file in other .mm file.

    The problem lies in the abc.h header itself, if I am writing below in abc.h :

    #include<set>

    #include<vector>

    Then on compilation of abc.h header file, it is throwing error that set and vector are not found.

Add a Comment

You might want to use the extension .hh to distinguish between Obj-C and Obj-C++ headers.

Or, if you want one header to be usable from both [Objective-]C++ and [Objective-]C, add a guard:

#if defined(__cplusplus)

… do C++ specific stuff …

#endif

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

on compilation of abc.h header file

try renaming it to .hh.

I have tried using .hh file extension but facing the same error.