Xcode 5 和 iOS 7:架构和有效架构

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18913906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:27:30  来源:igfitidea点击:

Xcode 5 and iOS 7: Architecture and Valid architectures

iphoneiosxcodeios7

提问by Crazy Yoghurt

I'm starting new project in Xcode 5. I want to develop application using iOS SDK 7but with deployment target iOS 5.0. As soon as I create new project in Xcode and try to change deployment target to 5.0, I've got this message:

我正在 Xcode 5 中开始新项目。我想使用iOS SDK 7但使用部署目标开发应用程序iOS 5.0。一旦我在 Xcode 中创建新项目并尝试将部署目标更改为 5.0,我就会收到以下消息:

Applications including an arm64 slice are not compatible with versions of iOS
prior to 6.0
Adjust your Architectures build setting to not include arm64 in order to deploy
to releases prior to iOS 6.0.

So changed architectures to Standard(no 64bit). I compiles, runs but I do not really understand what just happend.

What's the difference between Architecturesand Valid architecturessettings in Xcode project Build Settings?
If I set Architecturesto exclude 64-bit what happens when I run my app on 64-bit iPhone or iOS Simulator (I know it works, I'm just curious what hapens underneath)?
Can you explain big mess with new 64-bit architecture?

因此将架构更改为Standard(无 64 位)。我编译,运行,但我真的不明白刚刚发生了什么。Xcode 项目 Build Settings 中的和设置有

什么区别?如果我设置排除 64 位,当我在 64 位 iPhone 或 iOS 模拟器上运行我的应用程序时会发生什么(我知道它可以工作,我只是好奇下面发生了什么)?你能解释一下新的 64 位架构的大混乱吗?ArchitecturesValid architectures
Architectures

enter image description here

在此处输入图片说明

回答by Anil Varghese

Set the architecture in build setting to Standard architectures(armv7,armv7s)

将构建设置中的架构设置为 标准架构(armv7,armv7s)

enter image description here

在此处输入图片说明

iPhone 5S is powered by A7 64bit processor. From apple docs

iPhone 5S 搭载 A7 64 位处理器。来自苹果文档

Xcode can build your app with both 32-bit and 64-bit binaries included. This combined binary requires a minimum deployment target of iOS 7 or later.

Note: A future version of Xcode will let you create a single app that supports the 32-bit runtime on iOS 6 and later, and that supports the 64-bit runtime on iOS 7.

Xcode 可以构建包含 32 位和 64 位二进制文​​件的应用程序。此组合二进制文件需要 iOS 7 或更高版本的最低部署目标。

注意:Xcode 的未来版本将允许您创建一个应用程序,该应用程序支持 iOS 6 及更高版本上的 32 位运行时,并支持 iOS 7 上的 64 位运行时。

From the documentation what i understood is

从文档中我理解的是

  • Xcode can create both 64bit 32bit binaries for a single app but the deployment target should be iOS7. They are saying in future it will be iOS 6.0
  • 32 bit binary will work fine in iPhone 5S(64 bit processor).
  • Xcode 可以为单个应用程序创建 64 位 32 位二进制文​​件,但部署目标应该是 iOS7。他们说将来会是 iOS 6.0
  • 32 位二进制文​​件在 iPhone 5S(64 位处理器)中可以正常工作。

Update (Xcode 5.0.1)
In Xcode 5.0.1 they added the support to create 64 bit binary for iOS 5.1.1 onwards.

更新 (Xcode 5.0.1)
在 Xcode 5.0.1 中,他们添加了为 iOS 5.1.1 以后创建 64 位二进制文​​件的支持。

Xcode 5.0.1 can build your app with both 32-bit and 64-bit binaries included. This combined binary requires a minimum deployment target of iOS 5.1.1 or later. The 64-bit binary runs only on 64-bit devices running iOS 7.0.3 and later.

Xcode 5.0.1 可以构建包含 32 位和 64 位二进制文​​件的应用程序。此组合二进制文件要求最低部署目标为 iOS 5.1.1 或更高版本。64 位二进制文​​件仅在运行 iOS 7.0.3 及更高版本的 64 位设备上运行。

Update (Xcode 5.1)
Xcode 5.1 made significant change in the architecture section. This answerwill be a followup for you. Check this

更新 (Xcode 5.1)
Xcode 5.1 在架构部分进行了重大更改。这个答案将是你的后续。 检查这个

回答by sw_engineer

My understanding from Apple Docs.

我对 Apple Docs 的理解。

  • What is Architectures(ARCHS) into Xcode build-settings?
    • Specifies architecture/s to which the binary is TARGETED. When specified more that one architecture, the generated binary may contain object code for each of the specified architecture.
  • What is Valid Architectures(VALID_ARCHS) into Xcode build-settings?

    • Specifies architecture/s for which the binary may be BUILT.
    • During build process, this list is intersected with ARCHS and the resulting list specifies the architectures the binary can run on.
  • Example :- One iOS project has following build-settings into Xcode.

    • ARCHS = armv7 armv7s
    • VALID_ARCHS = armv7 armv7s arm64
    • In this case, binary will be built for armv7 armv7s arm64 architectures. But the same binary will run on ONLY ARCHS = armv7 armv7s.
  • Xcode 构建设置中的架构(ARCHS)是什么?
    • 指定体系结构/ s到该二进制靶向。当指定多个架构时,生成的二进制文件可能包含每个指定架构的目标代码。
  • Xcode 构建设置中的有效架构(VALID_ARCHS)是什么?

    • 指定体系结构/秒的量,二进制可BUILT
    • 在构建过程中,此列表与 ARCHS 相交,结果列表指定了二进制文件可以运行的架构。
  • 示例:- 一个 iOS 项目在 Xcode 中具有以下构建设置。

    • ARCHS = armv7 armv7s
    • VALID_ARCHS = armv7 armv7s arm64
    • 在这种情况下,将为 armv7 armv7s arm64 架构构建二进制文件。但是相同的二进制文件只能在 ARCHS = armv7 armv7s 上运行。

回答by Kibernetik

You do not need to limit your compiler to only armv7and armv7sby removing arm64setting from supported architectures. You just need to set Deployment targetsetting to 5.1.1

您不需要通过从支持的体系结构中删除arm64设置来将编译器限制为仅armv7armv7s。您只需要将部署目标设置设置为 5.1.1

Important note: you cannot set Deployment target to 5.1.1 in Build Settingssection because it is drop-down only with fixed values. But you can easily set it to 5.1.1 in Generalsection of application settings by just typing the value in text field.

重要提示:您不能在Build Settings部分将 Deployment target 设置为 5.1.1,因为它是只有固定值的下拉列表。但您只需在文本字段中键入值,即可在应用程序设置的“常规”部分轻松将其设置为 5.1.1 。

回答by Technologeeks

When you set 64-bit the resulting binary is a "Fat" binary, which contains all three Mach-O images bundled with a thin fat header. You can see that using otool or jtool. You can check out some fat binaries included as part of the iOS 7.0 SDK, for example the AVFoundation Framework, like so:

当您设置 64 位时,生成的二进制文件是一个“胖”二进制文件,其中包含所有三个 Mach-O 图像,并带有一个瘦胖头。您可以看到使用 otool 或 jtool。您可以查看一些包含在 iOS 7.0 SDK 中的胖二进制文件,例如 AVFoundation Framework,如下所示:

% cd  /Developer/Platforms/iPhoneOS.platform/DeviceSupport/7.0\ \(11A465\)/Symbols/System/Library/Frameworks/AVFoundation.framework/

%otool -V -f AVFoundation                                                                     9:36
Fat headers
fat_magic FAT_MAGIC
nfat_arch 3
architecture arm64     # The 64-bit version (A7)
    cputype CPU_TYPE_ARM64
    cpusubtype CPU_SUBTYPE_ARM64_ALL
    capabilities 0x0
    offset 16384
    size 2329888
    align 2^14 (16384)
architecture armv7        # A5X - packaged after the arm64version
    cputype CPU_TYPE_ARM
    cpusubtype CPU_SUBTYPE_ARM_V7
    capabilities 0x0
    offset 2359296
    size 2046336
    align 2^14 (16384)
architecture armv7s       # A6 - packaged after the armv7 version
    cputype CPU_TYPE_ARM
    cpusubtype CPU_SUBTYPE_ARM_V7S
    capabilities 0x0
    offset 4407296
    size 2046176
    align 2^14 (16384)

As for the binary itself, it uses the ARM64 bit instruction set, which is (mostly compatible with 32-bit, but) a totally different instruction set. This is especially important for graphics program (using NEON instructions and registers). Likewise, the CPU has more registers, which makes quite an impact on program speed. There's an interesting discussion in http://blogs.barrons.com/techtraderdaily/2013/09/19/apple-the-64-bit-question/?mod=yahoobarronson whether or not this makes a difference; benchmarking tests have so far clearly indicated that it does.

至于二进制本身,它使用 ARM64 位指令集,这是(大部分与 32 位兼容,但)完全不同的指令集。这对于图形程序(使用 NEON 指令和寄存器)尤其重要。同样,CPU 有更多的寄存器,这对程序速度影响很大。http://blogs.barrons.com/techtraderdaily/2013/09/19/apple-the-64-bit-question/?mod=yahoobarrons 中有一个有趣的讨论,讨论这是否有所不同;到目前为止,基准测试已经清楚地表明它确实如此。

Using otool -tV will dump the assembly (if you have XCode 5 and later), and then you can see the instruction set differences for yourself. Most (but not all) developers will remain agnostic to the changes, as for the most part they do not directly affect Obj-C (CG* APIs notwithstanding), and have to do more with low level pointer handling. The compiler will work its magic and optimizations.

使用 otool -tV 将转储程序集(如果您有 XCode 5 及更高版本),然后您可以自己查看指令集差异。大多数(但不是全部)开发人员对这些更改仍然不可知,因为在大多数情况下,它们不会直接影响 Obj-C(尽管有 CG* API),并且必须通过低级指针处理做更多的事情。编译器将发挥它的魔力和优化。

回答by Maselko

Simple fix:

简单的修复:

Targets -> Build Settings -> Build Options -> Enable Bitcode -> No

目标 -> 构建设置 -> 构建选项 -> 启用位码 -> 否

Works on device with iOS 9.3.3

适用于 iOS 9.3.3 设备

回答by tsuz

None of the answers worked and then I was forgetting to set minimum deployment target which can be found in Project-> General-> Deployment Info-> Deployment Target-> 8.0

没有一个答案有效,然后我忘记设置最小部署目标,可以在项目->常规->部署信息->部署目标-> 8.0 中找到

Example

例子