If you use XCode and have to deal with C++, Objective-C and Objective-C++ you might one day come across utterly mind-bending compiler errors that seem to defy logic. Weird things like header files not being found, or GCC somehow forgetting what the keyword ‘class’ or ‘template’ means.
And it can take hours of head-banging to work out the cause. So here’s a hint…
Make sure XCode thinks your source is the correct type. Is it compiling your crazy mix of C++ and Objective-C as Objective-C++, or has it got in a mess and is trying to compile it as Objective-C?
This can happen quite innocently if you hand create an Objective-C++ source file and name it foo.m instead of foo.mm. Especially since nothing bad will happen until you try to #include something that somewhere eventually #includes some C++. So you might have a load of Obj-C that through a chain of #includes/#imports eventually tries to use some C++. And then it’ll all go wrong.
You’ll know it’s gone wrong when illogical things happen. Things like a file that used to work fine suddenly no longer compiles, even though you’ve not altered anything inside it (all you did was #include it).
Time to find bug – ten minutes. Time to fix bug – less than a second.
Coming next… how to find the location of those bizarre backward_warning.h #warnings.



