本文介绍了位码和dylib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译一个C库以在我的iOS项目中使用它,并且我想嵌入位代码。



我可以针对每个Arch成功构建静态库。那些静态库确实包含位代码(已使用otool进行了检查),但是动态库不包含位代码。为什么? dylib不支持位代码吗?



我要构建的库是xz。这是脚本

  build_iOS()
{
ARCH = $ 1

如果[$ ARCH == i386] || [$ ARCH == x86_64];
然后
SDKROOT = $(xcodebuild -version -sdk iphonesimulator | grep -E'^ Path'| sed's / Path://')
否则
SDKROOT = $(xcodebuild -version -sdk iphoneos | grep -E'^ Path'| sed's / Path://')
fi

export CC = $(xcrun -sdk iphoneos -find clang)
export CFLAGS = -fembed-bitcode -isysroot $ SDKROOT -arch $ {ARCH} -miphoneos-version-min = 9.0
export LDFLAGS =-arch $ {ARCH} -isysroot $ SDKROOT

如果[$ ARCH == i386] || [$ ARCH == x86_64];
然后
./configure --prefix = $ XZPATH / build / iOS / $ ARCH --host = i686-apple-darwin11 --disable-static --enable-shared
else
./configure --prefix = $ XZPATH / build / iOS / $ ARCH --host = arm-apple-darwin --disable-static --enable-shared
fi

制造&&进行安装和安装清理
}
build_iOS i386
build_iOS x86_64
build_iOS armv7
build_iOS armv7s
build_iOS arm64


谢谢!

解决方案

似乎我无法添加位码dylibs。我尝试构建多个dylib,然后使用 otool -l path_to_dylib | grep位代码来测试它们是否包含任何位代码。



更多证据:



在Xcode(7.3.1)中的

  • 中,macOS(以前称为OS X)目标在构建设置中没有启用bitcode选项
  • 的位代码部分,Apple并未在macOS上提及比特码。另外,App Thinning仅在iOS,watchOS和tvOS上可用。


我目前不知道为什么macOS应用程序没有在构建设置中启用位码选项。也许是因为Mac App Store不是分发Mac应用程序的唯一方法?人们可能会使用USB记忆棒将一个Mac应用程序从一个Mac应用程序复制到另一个Mac应用程序?


I am trying to compile a C library to use it in my iOS project, and I want to embed bitcode.

I can successfully build static libraries targeting each arch. And those static library do contain bitcode (checked using otool), but the dynamic library doesn't contain bitcode. Why? Is bitcode not supported in dylib?

The library I am trying to build is xz. Here is the script

build_iOS()
{
    ARCH=$1

    if [ $ARCH == "i386" ] || [ $ARCH == "x86_64" ];
    then
        SDKROOT="$(xcodebuild -version -sdk iphonesimulator | grep -E '^Path' | sed 's/Path: //')"
    else
        SDKROOT="$(xcodebuild -version -sdk iphoneos | grep -E '^Path' | sed 's/Path: //')"
    fi

    export CC="$(xcrun -sdk iphoneos -find clang)"
    export CFLAGS="-fembed-bitcode -isysroot $SDKROOT -arch ${ARCH} -miphoneos-version-min=9.0"
    export LDFLAGS="-arch ${ARCH} -isysroot $SDKROOT"

    if [ $ARCH == "i386" ] || [ $ARCH == "x86_64" ];
    then
        ./configure --prefix=$XZPATH/build/iOS/$ARCH --host=i686-apple-darwin11 --disable-static --enable-shared
    else
        ./configure --prefix=$XZPATH/build/iOS/$ARCH --host=arm-apple-darwin --disable-static --enable-shared
    fi

    make && make install && make clean
}
build_iOS i386
build_iOS x86_64
build_iOS armv7
build_iOS armv7s
build_iOS arm64

Thanks!

解决方案

It looks like I cannot add bitcode to dylibs. I tried building several dylibs, then use otool -l path_to_dylib | grep bitcode to test if they contain any bitcode, all got nothing.

More evidence:

  • in Xcode(7.3.1), macOS (previously called OS X) targets don't have enable bitcode option in build settings
  • in the bitcode section of App Thinning, Apple didn't mentioned bitcode on macOS. Plus, App Thinning is only available on iOS, watchOS and tvOS.

I currently don't know why macOS apps don't have enable bitcode option in build setting. Maybe it's because Mac App store is not the only way for distributing mac apps? And people might copy one mac app from one mac app to another using USB sticks?

这篇关于位码和dylib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 06:29