views:

385

answers:

1

I have a few lines of assembler arm code in an .s file. Just a few routines i need to call. It works fine when building for the device, however when i switch to iPhone Simulator i get "no such instruction" errors. I tried to compile parts of the .s file conditionally with what i know:

#if !TARGET_IPHONE_SIMULATOR

But the assembler doesn't recognize these preprocessor directives (of course) and none of the conditional compilation techniques for assembler that i could remember or find worked, so i'm scratching my head now on how to avoid compilation of that assembler code when building for the Simulator. I also don't see a project option in Xcode that would allow me to compile the file or not depending on the target platform.

SOLVED:

All i was missing was the proper #import in the assembler file. I did not think of adding it because Xcode syntax highlighted any preprocessor directive in green (comment) which made me assume that these commands are not recognized when in fact they work just fine.

This works:

#import "TargetConditionals.h"

#if !TARGET_IPHONE_SIMULATOR

... asm code here ...

#endif
+1  A: 

You do do it with a pre-processor macro. They are defined in TargetConditionals.h TARGET_IPHONE_SIMULATOR should be there! (You do need to #include it however.)

Andiih
Yes, of course it's there ... but the #if preprocessor directive isn't. It works in C/ObjC code but not in assembler .s files.
GamingHorror
Actually ... by adding #import "TargetConditionals.h" it works! I was confused because Xcode did not properly syntax highlight the preprocessor macros.
GamingHorror
Thanks GH. I will edit my answer to make it clearer that TargetConditionals.h needs to be included.
Andiih