Dan Groom Dan Groom - 2 months ago 15
iOS Question

Which compiler settings are changed when I change target device?

I have an iOS project that builds fine for simulators, but which has compiler errors when built for a Generic Device or when I try to run on a real device through Xcode. NOTE: actual compiler errors, not linker or deployment errors. The errors are to do with mismatched types in typedefs - as if it's including headers from a different SDK, or has different preprocessor defines.

My question is - what compiler settings are changed when I change target device in the Xcode UI and where can I view the differences? I cannot see any differences when I look at the project settings and change the target device - specifically the deployment target version and SDK version appear unchanged.

The project used to build fine with any of these target devices under Xcode 7, but does not under Xcode 8. I suspect this is down to the version of the SDK that comes with Xcode. But for it to work with some target devices and not others it has to be changing compiler settings. This should be really simple to fix, if only I could see what changes it's making!

Here's the line (in my code) which fails to compile:

typedef void* IOSurfaceRef;

And here's the error message:

error: typedef redefinition with different types ('void *' vs 'struct __IOSurface *')

Please note I don't want help fixing the error or advice on what it's trying to do - I know it's not good. I'd just like to know which compiler settings are changed by switching target device.

dan dan

It fails because CGBase.h contains this code:


typedef struct  CF_BRIDGED_TYPE(id) __IOSurface *IOSurfaceRef __attribute__((swift_name("IOSurfaceRef")));


When you are building for a device the #if !TARGET_IPHONE_SIMULATOR preprocessor directive is true, so your code has two typedefs for IOSurfaceRef with conflicting types.