xcode 如何使用 bitcode 选项制作胖框架?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33106117/
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
How do i make fat framework with bitcode option?
提问by Deepak Badiger
Environment: XCode 7.0.1 Module: Objective-C Bundle Type: Framework
环境:XCode 7.0.1 模块:Objective-C 捆绑类型:框架
Hi, I am trying to create a framework to support armv7, armv7s, arm64, i386 and x86_64. I am using aggregate to make the fat library. Inside the aggregate script, i am running two xcodebuild commands 1. for armv7, armv7s and arm64 and 2. for i386 and x86_64 architectures. Also, I have set Enable Bitcode=YES and Other C Flags=-fembed-bitcode under target build settings. As a precautionary mesasure, i am adding ENABLE_BITCODE=YES and OTHER_CFLAGS="-fembed-bitcode" options to the xcodebuild command
嗨,我正在尝试创建一个框架来支持 armv7、armv7s、arm64、i386 和 x86_64。我正在使用聚合来制作胖库。在聚合脚本中,我正在运行两个 xcodebuild 命令 1. 用于 armv7、armv7s 和 arm64 以及 2. 用于 i386 和 x86_64 架构。另外,我在目标构建设置下设置了 Enable Bitcode=YES 和 Other C Flags=-fembed-bitcode 。作为预防措施,我在 xcodebuild 命令中添加了 ENABLE_BITCODE=YES 和 OTHER_CFLAGS="-fembed-bitcode" 选项
My xcode build commands are as follows -
我的 xcode 构建命令如下 -
#Build The framework Target for iPhoneOS
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${AN_TARGET}"
ONLY_ACTIVE_ARCH=NO -configuration "${CONFIGURATION}" -sdk iphoneos
BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}"
CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}" SYMROOT="${SYMROOT}"
ARCHS="armv7 armv7s arm64" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" $ACTION
#Build The framework Target for iPhoneSimulator
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${AN_TARGET}"
ONLY_ACTIVE_ARCH=NO -configuration "${CONFIGURATION}" -sdk iphonesimulator
BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}"
CONFIGURATION_BUILD_DIR="${IPHONE_SIMULATOR_BUILD_DIR}" SYMROOT="${SYMROOT}"
ARCHS="i386 x86_64" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" $ACTION
after running the above two commands, i am combining these two builds to make a fat framework binary using the below command
运行上述两个命令后,我将这两个构建结合起来使用以下命令制作一个胖框架二进制文件
# create a fat Framework
lipo -create
"${IPHONE_DEVICE_BUILD_DIR}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
"${IPHONE_SIMULATOR_BUILD_DIR}/${PROJECT_NAME}.framework/${PROJECT_NAME}" -
output "${FRAMEWORK_FOLDER}/${AN_END_USER_FRAMEWORK_NAME}"
The issue iam facing is after the lipo is created, i am unable to use it in the bitcode enabled application. After running the otool -l framework_binary | grep -LLVM
, i do not see the bitcode enabled flags or __LLVM.
我面临的问题是在创建 lipo 之后,我无法在启用位码的应用程序中使用它。运行后otool -l framework_binary | grep -LLVM
,我没有看到启用位码的标志或 __LLVM。
Lipo removes bitcode from the fat binary. Is there a way i can retain bitcode while running the lipo command?
Lipo 从胖二进制文件中删除位代码。有没有办法在运行 lipo 命令时保留位码?
Correction: Based on the reply from Nestor, i ran the otool command as otool -l -arch armv7 framework_binary | grep LLVM
and much to my surprise, i could see the segname __LLVM clang. However when i integrate the same fat framework binary into my project, it builds fine on simulator however throws the following error while running on device - ld: 'MyBinary' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture armv7
更正:根据 Nestor 的回复,我运行了 otool 命令,otool -l -arch armv7 framework_binary | grep LLVM
令我惊讶的是,我可以看到 segname __LLVM clang。但是,当我将相同的胖框架二进制文件集成到我的项目中时,它在模拟器上构建良好,但是在设备上运行时会引发以下错误 - ld:'MyBinary' 不包含位码。您必须在启用位码的情况下重建它(Xcode 设置 ENABLE_BITCODE),从供应商处获取更新的库,或为此目标禁用位码。用于架构 armv7
回答by David Cortes
This is something weird, there are not many documentation for do this, at the end I use this command:
这很奇怪,没有很多文档可以做到这一点,最后我使用这个命令:
xcodebuild -project ${PROJECT_NAME}.xcodeproj -target ${FRAMEWORK_NAME} ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode FRAMEWORK_SEARCH_PATHS="${FRAMEWORK_SEARCH_PARTH} ${SRCROOT}/**" -sdk ${SIMULATOR_SDK} -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-${SIMULATOR_SDK} 2>&1
xcodebuild -project ${PROJECT_NAME}.xcodeproj -target ${FRAMEWORK_NAME} -sdk ${DEVICE_SDK} ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode FRAMEWORK_SEARCH_PATHS="${FRAMEWORK_SEARCH_PARTH} ${SRCROOT}/**" -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-${DEVICE_SDK} 2>&1
Add the BITCODE_GENERATION_MODE=bitcode flag to the xcodebuild command
将 BITCODE_GENERATION_MODE=bitcode 标志添加到 xcodebuild 命令
回答by Nestor
Happily it's just a problem with otool
's reporting, not lipo
; you have to add the -arch
parameter:
令人高兴的是,这只是otool
's 报告的问题,而不是lipo
; 你必须添加-arch
参数:
otool -arch arm64 -l myLipoOutput.a
回答by Cosmin
Try to use archive for the arm slices instead of build
尝试对手臂切片使用存档而不是构建
xcodebuild -scheme "${SCHEME}" -workspace "${WORKSPACE}" -configuration "${CONFIGURATION}" -sdk iphoneos ARCHS="arm64 armv7 armv7s" CONFIGURATION_BUILD_DIR="${CONFIGURATION_BUILD_DIR}/arm" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO ONLY_ACTIVE_ARCH=NO archive
After that run lipo to merge the simulator and the arm ones.
之后运行 lipo 以合并模拟器和手臂。
And after that run otool -arch arm64 -l myLipoOutput.a
and it should work.
在那次运行之后,otool -arch arm64 -l myLipoOutput.a
它应该可以工作。
回答by silyevsk
It looks like a bug in Xcode 7.0.1 . I've had the same issue and downgrading Xcode to version 7 fixed it.
它看起来像是 Xcode 7.0.1 中的一个错误。我遇到了同样的问题,将 Xcode 降级到版本 7 修复了它。
Update:Actually it may be a bug in Xcode 7 that was fixed in 7.0.1 - this SO answersolved the issue for me.
更新:实际上,这可能是 Xcode 7 中的一个错误,该错误已在 7.0.1 中修复 -这个 SO 答案为我解决了这个问题。