编译启用了bitcode的iOS库

时间:2015-09-30 14:09:17

标签: ios frameworks bitcode

我需要发布一个启用了bitcode的框架,结果很麻烦。我设置了启用Bitcode'在项目的设置中,“是”'它可以为真实设备和模拟器提供干净的构建。

我想测试库,所以我将它集成到我为此目的创建的新应用程序中,但现在它只为模拟器构建。当我尝试为真实设备构建时,我得到了:

ld: '/path/to/Framework.framework/Company(File.o)' 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
clang: error: linker command failed with exit code 1 (use -v to see invocation)

就像我说的那样,我用Bitcode启用了它,所以我不确定为什么会这样。

有什么想法吗?感谢

3 个答案:

答案 0 :(得分:19)

AFAIK,当您使用Xcode构建应用程序时,它仅在您进行存档时包含Bitcode,原因是 - 只需要调试或测试应用程序/库时减少编译时间。

为确保Xcode在每次构建时都会发出bitcode,您可以将-fembed-bitcode标记添加到Other C flagsOther linker flags

enter image description here

enter image description here

此外,检查二进制文件是否包含bitcode的最简单方法是使用otoolgrep

otool -l binary_name | grep __LLVM

如果没有bitcode,则会看到一个或多个segname __LLVM条目,如果没有,则会看到空输出。

答案 1 :(得分:1)

要使用xcodebuild命令启用位码,您必须添加

BITCODE_GENERATION_MODE=bitcode.

找到以下命令

xcodebuild BITCODE_GENERATION_MODE=bitcode -target TARGETNAME ONLY_ACTIVE_ARCH=NO -configuration Release -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"

答案 2 :(得分:-1)

RunScript代码的另一种方法:(构建设置 - 构建阶段RunScript) enter image description here

# define output folder environment variable
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

# Step 1. Build Device and Simulator versions
xcodebuild -target TARGETNAME ONLY_ACTIVE_ARCH=NO -configuration Release -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target TARGETNAME -configuration Release -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"

# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

# Step 2. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a"

# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"