Static Libs With Support to iOS 5 and Arm64

With the launch of iPhone 5s Apple brings the 64-bit architecture to mobile, this brings new possibilities for the iOS platform. But there is a restriction imposed by Apple, only projects with deployment target to iOS 6.0 or higher can produce fat binaries including arm64. So the apps developer should choose between support iOS 5 and earlier or arm64, although SDK developers shouldn’t be obligated to decide for your users! It’s possible to produce one fat binary with all the architectures, so let’s see one way to do it.

There is a discussion on Developer Forums where an Apple developer explains that this restriction is due to iOS 5 are not prepared to handle the fat binary headers that contain 64-bit code. Although static libraries aren’t handled by iOS but by the linker that came with Xcode and Xcode 5 linker obviously can handle 64-bit code!

The idea is pretty simple, build the different architectures separated then bind them using lipo. I know that is possible to do this using directly the Xcode, but I prefer to do it via command line (or Rakefile).

First build the binary with arm using xcodebuild:

xcodebuild -project 'MCLog.xcodeproj' -configuration 'Release' -sdk 'iphoneos8.2' clean build ARCHS='armv7 armv7s' IPHONEOS_DEPLOYMENT_TARGET='5.0' TARGET_BUILD_DIR='./build-arm' BUILT_PRODUCTS_DIR='./build-arm'


Note that you must set IPHONEOS_DEPLOYMENT_TARGET='5.0' and ARCHS='armv7 armv7s', it’s recommended to set build and product dirs to make the things more clear, take a look at Build Setting Reference for more details what this flags means.

Next build for arm64:

xcodebuild -project 'MCLog.xcodeproj' -configuration 'Release' -sdk 'iphoneos8.2' clean build ARCHS='arm64' IPHONEOS_DEPLOYMENT_TARGET='7.0' TARGET_BUILD_DIR='./build-arm64' BUILT_PRODUCTS_DIR='./build-arm64'

Note the difference on  ARCHS  and  IPHONEOS_DEPLOYMENT_TARGET . We also need to build for simulator, in this case we have to change the sdk to  iphonesimulator7.0  and build in two steps first for  i386 :

xcodebuild -project 'MCLog.xcodeproj' -configuration 'Release' -sdk 'iphonesimulator8.2' clean build ARCHS='i386' IPHONEOS_DEPLOYMENT_TARGET='5.0' TARGET_BUILD_DIR='./build-i386' BUILT_PRODUCTS_DIR='./build-i386'

Now the tricky part! If you just change the  ARCHS  to  x86_86  depending on your Xcode setting you will got an error like: “x86_64 is not a valid arch”. To avoid this just add  VALID_ARCHS='x86_64' :

xcodebuild -project 'MCLog.xcodeproj' -configuration 'Release' -sdk 'iphonesimulator8.2' clean build ARCHS='x86_64' IPHONEOS_DEPLOYMENT_TARGET='7.0' TARGET_BUILD_DIR='./build-x86_64' BUILT_PRODUCTS_DIR='./build-x86_64' 


Finally we just have to create a fat binary with all the 5 architectures:

lipo -create './build-arm/libMCLog.a' './build-arm64/libMCLog.a' './build-i386/libMCLog.a' './build-x86_64/libMCLog.a' -output 'libMCLog.a'

lipo -info libMCLog.a





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
STATIC_LIBS是一个编译时所依赖的静态库列表。在Android NDK中,可以使用cc_library_shared来编译动态库,使用cc_binary来编译可执行文件。在cc_library_shared或cc_binary的配置中,可以通过static_libs参数来指定所依赖的静态库。这些静态库将会被链接到最终的可执行文件或动态库中,以提供所需的功能和符号。\[3\] #### 引用[.reference_title] - *1* [【Android】编译系统之 make 和 Soong](https://blog.csdn.net/yang553566463/article/details/126603493)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Android 静态库互相依赖问题](https://blog.csdn.net/weixin_40437029/article/details/107713761)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Android.bp文件简介](https://blog.csdn.net/qq_29890089/article/details/121124416)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值