美文网首页
iOS指令集总结

iOS指令集总结

作者: 大圣的如意棒 | 来源:发表于2017-01-01 16:58 被阅读1134次

    指令集

    通常会把CPU的扩展指令集称为”CPU的指令集”(因为基本的,类似加减的指令似乎是必须被CPU所支持的指令)。每款CPU在设计时就规定了一系列与其硬件电路相配合的指令集。

    Arm处理器

    Arm处理器,因为其低功耗和小尺寸而闻名,几乎所有的手机处理器都基于arm,其在嵌入式系统中的应用非常广泛,它的性能在同等功耗产品中也很出色。想了解ARM指令集的请点击这里

    iPhone指令集

    苹果A7处理器支持两个不同的指令集:32位ARM指令集(armv6|armv7|armv7s)和64位ARM指令集(arm64),i386|x86_64 是Mac处理器的指令集,i386是针对intel通用微处理器32架构的。x86_64是针对x86架构的64位处理器。当使用iOS模拟器的时候会遇到i386|x86_64,iOS模拟器没有arm指令集。

    不同型号的iPhone都使用的是什么指令集:

    ARMv8-A = iPhone6s,iPhone6s Plus,iPad Air2,Apple TV4,iPad Air,iPhone6         

    ARMv8/ARM64 = iPhone5s, iPad Air, Retina iPad MiniARMv7s = iPhone5, iPhone5c, iPad4

    ARMv7  = iPhone3GS, iPhone4, iPhone4S, iPod3G/4G/5G, iPad, iPad2, iPad3, iPad Mini  

    ARMv6  = iPhone, iPhone3G, iPod1G/2G


    Xcode中关于生成二进制包指令集相关的设置

    主要有以下三个:

    Architectures

    官方文档说明:

    Space-separated list of identifiers. Specifies the architectures (ABIs, processor models) to which the binary is targeted. When this build setting specifies more than one architecture, the generated binary may contain object code for each of the specified architectures.

    该编译选项指定了工程将被编译成支持哪些指令集,支持指令集是通过编译生成对应的二进制数据包实现的,如果支持的指令集数目有多个,就会编译出包含多个指令集代码的数据包,造成最终编译的包很大。

    Valid Architectures

    官方文档说明:

    Space-separated list of identifiers. Specifies the architectures for which the binary may be built. During the build, this list is intersected with the value of ARCHS build setting; the resulting list specifies the architectures the binary can run on. If the resulting architecture list is empty, the target generates no binary.

    该编译项指定可能支持的指令集,该列表和Architectures列表的交集,将是Xcode最终生成二进制包所支持的指令集。

    比如,你的Valid Architectures设置的支持arm指令集版本有:armv7/armv7s/arm64,对应的Architectures设置的支持arm指令集版本有:armv7s,这时Xcode只会生成一个armv7s指令集的二进制包。

    Build Active Architecture Only

    官方文档说明:

    Boolean value. Specifies whether the product includes only object code for the native architecture.

    该编译项用于设置是否只编译当前使用的设备对应的arm指令集。

    当该选项设置成YES时,你连上一个armv7指令集的设备,就算你的Valid Architectures和Architectures都设置成armv7/armv7s/arm64,还是依然只会生成一个armv7指令集的二进制包。

    当然该选项起作用的前提是你的Xcode必须成功连接了调试设备。如果你没有任何活跃设备,即Xcode没有成功连接调试设备,就算该设置项设置成YES依然还会编译Valid Architectures和Architectures指定的二进制包。

    通常情况下,开发测试都是在 Debug模式下,所以该编译选项在Debug模式都设成YES,这样在测试时只编译一份指令集,有效提高开发效率。

    Release模式为发布模式,需要支持各种设备指令集,所以设置为NO。

    说明:

    指令集都是可以向下兼容的

    比如,你的设备是ARMv8指令集,那么它也可以兼容运行比armv7s版本低的指令集:armv7、armv6


    关于指令集的常见问题:

    1.导入静态库后编译报错,Undefined symbols for architecture x86_64:

    原因:

    1:可能是静态库中不包含这个类。

    2:静态库工程可能没有链接到应用。

    3:   静态库不支持模拟器运行;

    解决办法:

    1:查看静态库里面是否存在这个类。

    2:Build Phases中没有添加Link Binary With Libraries 中添加此静态库。

    3:  在真机上运行进行测试(😄);或者对静态库进行修改,使其支持模拟器的运行,在静态库target的build Settings中设置Valid Architectures为armv7 arm64 armv7s i386 x86_64

    2. 使用 lipo -info 指令查看静态库支持的指令集

         如在命令行中输入: lipo -info  /test/libFireflyUI.a

    3.使用lipo -create指令来合并支持真机和模拟器的静态库

    如在命令行中输入:lipo -create 

    /Users/jinyy/Downloads/Release/iPhone_Device//libs/libFireflyUI.a

    /Users/jinyy/Downloads/Release/iPhone_Simulator//libs/libFireflyUI.a

    -output  /Users/jinyy/Downloads/Release/uinion/libFireflyUI.a


    相关文章

      网友评论

          本文标题:iOS指令集总结

          本文链接:https://www.haomeiwen.com/subject/dqjivttx.html