交叉编译和iphone的cpu架构

10 篇文章 0 订阅

1.交叉编译交叉编译呢,简单地说,就是在一个平台上生成另一个平台上的可执行代码。同一个体系结构可以运行不同的操作系统;同样,同一个操作系统也可以在不同的体系结构上运行。举例来说,我们常说的x86 Linux平台实际上是Intel x86体系结构和Linux for x86操作系统的统称;而x86 WinNT平台实际上是Intel x86体系结构和Windows NT for x86操作系统的简称。

要进行交叉编译,我们需要在主机平台上安装对应的交叉编译工具链(cross compilation tool chain),然后用这个交叉编译工具链编译我们的 源代码,最终生成可在目标平台上运行的代码。常见的交叉编译例子如下:
1、在Windows PC上,利用ADS(ARM  开发环境),使用armcc 编译器,则可编译出针对ARM CPU的 可执行代码
2、在Linux PC上,利用arm-linux-gcc 编译器,可编译出针对Linux ARM平台的 可执行代码
3、在Windows PC上,利用cygwin环境,运行arm-elf-gcc 编译器,可编译出针对ARM CPU的 可执行代码
在做实际工作之前,我想我们应该先掌握一些关于交叉编译的基本知识,其实说白了也就是理解一些我们经常会碰到的英文单词:
宿主机(host) :编辑和 编译程序的平台,一般是基于X86的PC机,通常也被称为主机。
目标机(target):用户开发的系统,通常都是非X86平台。host编译得到的 可执行代码在target上运行。
prefix:  交叉编译器的安装位置。
xxx-xxxx-xxxxx 平台描述。
我们在 主机平台上开发程序,并在这个平台上运行 交叉编译器,编译我们的程序;而由交叉编译器生成的程序将在目的平台上运行。这里值得说明得是平台描述,象arm-linux、i386-pc-linux2.4.3这样的字符串我们经常会看到,其实它是用来描述平台的,它有完整格式、缩减格式和别名之分。完整格式是:CPU-制造厂商- 操作系统,如sparc-sun-sunos4.1.4,说明平台所使用的CPU是sparc,制造厂商是sun,上面运行的操作系统是SunOS,版本是4.1.4。当然,我们都不愿记这么长的东西,因此可以使用短格式,短格式中有选择地去除了制造厂商、 软件版本等信息,因此我们同样可以用sparc-sunos或sparc-sunos-sunos4来描述这个平台。如果觉得这个还是太麻烦,那就可以使用别名,sun4m就可以很简单地描述这个平台。需要注意的是,并不是所有的平台都有别名,也不是所有的短格式都可以正确地描述平台。

2.

目前ios的指令集有以下几种:

  • armv6
    • iPhone
    • iPhone2
    • iPhone3G
    • 第一代和第二代iPod Touch
  • armv7
    • iPhone4
    • iPhone4S
  • armv7s
    • iPhone5
    • iPhone5C
  • arm64
    • iPhone5S

 机器对指令集的支持是向下兼容的,因此armv7的指令集是可以运行在iphone5S的,只是效率没那么高而已~

================================================

Architecture : 指你想支持的指令集。

Valid architectures : 指即将编译的指令集。

Build Active Architecture Only : 只是否只编译当前适用的指令集。

================================================

 现在是2014年初,其实4和4S的用户还是蛮多的,而iphone3之类的机器几乎没有了,所以我们的指令集最低必须基于armv7.

因此,Architecture的值选择:armv7 armv7s arm64

PS:选arm64时需要最低支持5.1.1:

Convert Your App to a 64-Bit Binary After Updating It for iOS 7

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. If you have an existing app, you should first update your app for iOS 7 and then port it to run on 64-bit processors. By updating it first for iOS 7, you can remove deprecated code paths and use modern practices. If you’re creating a new app, target iOS 7 and compile 32-bit and 64-bit versions of your app.

The architecture for 64-bit apps on iOS is almost identical to the architecture for OS X apps, making it easy to create a common code base that runs in both operating systems. Converting a Cocoa Touch app to 64-bit follows a similar transition process as the one for Cocoa apps on OS X. Pointers and some common C types change from 32 bits to 64 bits. Code that relies on the NSInteger and CGFloat types needs to be carefully examined.

Start by building the app for the 64-bit runtime, fixing any warnings that occur as well as searching your code for specific 64-bit issues. For example:

  • Make sure all function calls have a proper prototype.

  • Avoid truncating 64-bit values by accidentally assigning them to a 32-bit data type.

  • Ensure that calculations are performed correctly in the 64-bit version of your app.

  • Create data structures whose layouts are identical in the 32-bit and 64-bit versions of your app (such as when you write a data file to iCloud).

1,如果想自己的app在各个机器都能够最高效率的运行,则需要将Build Active Architecture Only改为NO,Valid architectures选择对应的指令集:armv7 armv7s arm64。这个会为各个指令集编译对应的代码,因此最后的 ipa体积基本翻了3倍,Release版本必须NO。

2,如果想让app体积保持最小,则现阶段应该选择Valid architectures为armv7,这样Build Active Architecture Only选YES或NO就无所谓了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值