【问题标题】:How to you prevent blocks of code from compiling on ARMv6 for a fat binary?如何防止代码块在 ARMv6 上编译为胖二进制文件?
【发布时间】:2010-12-09 11:53:59
【问题描述】:

我有一个 iPhone 项目,配置为针对 armv6 和 armv7 架构进行编译。而且我需要从编译 armv6 架构中排除一些代码,因为它会导致设备运行时崩溃(错误指令异常)。

是否有定义 armv6/armv7 编译路径(如“_DEBUG”)?

【问题讨论】:

  • 好问题。对于只能在 ARMv7 设备上运行的代码路径也很有用。

标签: iphone xcode armv6


【解决方案1】:

首先,你不需要阻止它们编译,你需要阻止它们被执行。崩溃是在运行时,毕竟不是编译时。

也就是说,最简单的方法是拥有两个代码路径,并根据架构编译相应的部分:

#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

【讨论】:

    【解决方案2】:

    一种解决方法可能是将所有仅支持 armv6 的源代码收集到一个子项目中并将它们编译为静态库,然后将该库链接到胖应用程序。

    也可以在 Xcode 中为每个源文件指定额外的构建标志,但我不熟悉语法或基本上恢复已发出的标志所需的其他内容(例如,指定在 armv7 下编译的标志。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-18
      相关资源
      最近更新 更多