我有一个 iPhone 项目,配置为针对 armv6 和 armv7 架构进行编译。我需要从编译 armv6 架构中排除一些代码,因为它会导致设备运行时崩溃(错误指令异常)。
是否有定义 armv6/armv7 编译路径(例如“_DEBUG”)?
首先,你不需要阻止它们编译,你需要阻止它们被执行。崩溃是在运行时,毕竟不是编译时。
也就是说,最简单的方法是有两个代码路径,并根据体系结构编译适当的部分:
#if defined _ARM_ARCH_7
// your armv7 implementation goes here
#elif defined _ARM_ARCH_6
// your armv6 implementation goes here
#elif defined __i386__
// a simulator implementation could go here, if you had one
#else
#error Unknown Architecture!
#endif
一种解决方法可能是将所有仅支持 armv6 的源代码收集到一个子项目中并将它们编译为静态库,然后将该库链接到胖应用程序。
还可以在 Xcode 中为每个源文件指定额外的构建标志,但我不熟悉语法或基本上恢复已经发出的标志所需的其他内容(例如,指定在 armv7 下编译的标志。)