Search code examples
c++xcodeiosbuild-processheader-files

Header imports and includes failing in XCode, cmath, objc-class.h, etc


I keep having issues with including basic headers such as cmath. It is most prevalent when using example projects. Example:

#include <cmath>

for instance gets a file not found, even though I can verify that the SDK I'm using has it:

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include/c++/4.2.1/tr1/cmath

I can sometimes work around the issue by importing directly to the file, but this doesn't always work.

#include </usr/include/c++/4.2.1/cmath>

Solution

  • What is the extension of your sourcecode file? .m or .mm? If it's .m, the compiler will assume you have a regular objective-C file, whereas .mm would imply an objective-C++ file. If its not a .mm file, the compiler may not be looking for C++ includes.