iPhone 的汇编 (.s) 代码中的条件编译 - 如何进行?
我在 .s 文件中有几行汇编器arm代码。只是我需要调用的一些例程。在为设备构建时它工作正常,但是当我切换到 iPhone Simulator 时,我收到“没有这样的指令”错误。我尝试用我所知道的有条件地编译 .s 文件的部分内容:
#if !TARGET_IPHONE_SIMULATOR
但是汇编器无法识别这些预处理器指令(当然),而且我记得或发现的汇编器条件编译技术都不起作用,所以我'我现在正在绞尽脑汁地思考如何在构建模拟器时避免编译该汇编程序代码。我也没有在 Xcode 中看到允许我根据目标平台编译或不编译文件的项目选项。
已解决:
我所缺少的是汇编程序文件中正确的#import。我没有想到添加它,因为 Xcode 语法以绿色突出显示了任何预处理器指令(注释),这让我假设这些命令未被识别,而实际上它们工作得很好。
这有效:
#import "TargetConditionals.h"
#if !TARGET_IPHONE_SIMULATOR
... asm code here ...
#endif
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用预处理器宏来完成此操作。它们在 TargetConditionals.h
TARGET_IPHONE_SIMULATOR
中定义,应该在那里! (但是你确实需要 #include 它。)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.)这是我用来检测 ARM、Thumb 与 Simulator 的代码:
// 以下是您如何使用它
Here is code I use to detect ARM vs Thumb vs Simulator:
// And here is how you might use it