Question

I am trying to develop a C++ library for an iOS application. This library loads the GLES and OpenAL functions. The idea is to develop a library in C++ and use the same code in iOS and Android (both as native compilation). I am only with the iOS implementation, and I have done a sample application with the library and I have this block inside the library:

#ifdef _IPHONE_4_0

    #warning "Including iPhone SDK 4.0 working here"     // compiling warning is actived

    #include    <OpenGLES/ES2/gl.h>
    #include    <OpenGLES/ES2/glext.h>

    #include    <OpenAL/al.h>
    #include    <OpenAL/alc.h>

    ...

#elif __ANDROID_API_ // Android

    #warning "Including Android working here"   // Compiling warning is not actived
        ...

#endif

So, the problem comes with the sentence "#ifdef _IPHONE_4_0". If I use it, Xcode can't find the include files, but if I comment all the if clausule (android part too) Xcode can find all of them.

#warning sentences shows that the compiler is reading the iphone part (with and without lines commented) in compilation time. Do I need to use the definition in other way?

Thanks in advance!

Was it helpful?

Solution

Check this post How to detect reliably Mac OS X, iOS, Linux, Windows in C preprocessor?

Also, as I know, __IPHONE_4_0 macro defined only in iOS 4.0 SDK. So the code should not work if you are using another version of SDK.

Another approach is define your own macro in Xcode project build settings ('Preprocessors macros' field) and name it IOS_BUILD, for example. It will be available in both - objective-c and c++ code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top