交叉编译为静态库 (libgcrypt) 以在 iOS 上使用 [英] Cross-compile to static lib (libgcrypt) for use on iOS

查看:39
本文介绍了交叉编译为静态库 (libgcrypt) 以在 iOS 上使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载了最新的 libgcrypt &来自 https://www.gnupg.org/download/index.html.我已经使用 ./configure --enable-static --disable-shared; 成功构建了(命令行)两个库;制作 ;在我的 Mac 上进行安装(Mavericks w/OSX 10.10 & 最新的 Xcode 6.1).

I have downloaded latest libgcrypt & libgpg-error libraries from https://www.gnupg.org/download/index.html. I have successfully built (command line) both libraries using ./configure --enable-static --disable-shared; make ; make install on my Mac (Mavericks w/OSX 10.10 & latest Xcode 6.1).

我可以很好地从我正在构建的 OS X 客户端应用程序链接到这些新库.到现在为止还挺好.刚刚好.但是,我还需要使用完全相同的源代码构建一个 iOS 客户端.

I can link just fine to these new libs from an OS X client app I am building. So far, so good. Just perfect. BUT, I also need to build an iOS client using same exact source code.

问题:

1) 我需要为(模拟器、Mac 和 iOS)构建通用静态库的库的命令行构建序列有哪些修改?2) 还是我需要为 iOS 构建单独的静态库?如果是这样,我需要什么命令行魔法才能使目标架构正确?

1) What are the modifications to the command line build sequence for the library I would need to build a universal static library for the (simulator, Mac & iOS)? 2) Or do I need to build separate static libs for iOS? And if so, again, what command line magic would I need to accomplish getting the target architecture right?

推荐答案

请注意,无法构建适用于 iOS 模拟器和 macOS 的通用库.iOS/Intel 和 macOS/Intel 与 C 运行时库 (Libc) 之上的 ABI 不兼容.此答案用于向您展示如何为 iOS 目标交叉编译基于 autoconf 的项目,并且您可以轻松地将生成的静态档案整合在一起.

Note that it is not possible to build a universal library that will work for both the iOS Simulator and macOS. iOS/Intel and macOS/Intel are not ABI compatible above the C runtime library (Libc). This answer serves to show you how to crosscompile autoconf based projects for iOS targets, and you can easily lipo the resulting static archives together.

你会想要做这样的事情:

You will want to do something like this:

#!/bin/bash -e -x

OPT_FLAGS="-Os -g3"
MAKE_JOBS=16

dobuild() {
    export CC="$(xcrun -find -sdk ${SDK} cc)"
    export CXX="$(xcrun -find -sdk ${SDK} cxx)"
    export CPP="$(xcrun -find -sdk ${SDK} cpp)"
    export CFLAGS="${HOST_FLAGS} ${OPT_FLAGS}"
    export CXXFLAGS="${HOST_FLAGS} ${OPT_FLAGS}"
    export LDFLAGS="${HOST_FLAGS}"

    ./configure --host=${CHOST} --prefix=${PREFIX} --enable-static --disable-shared

    make clean
    make -j${MAKE_JOBS}
    make install
}

SDK="iphoneos"
ARCH_FLAGS="-arch armv7"
HOST_FLAGS="${ARCH_FLAGS} -miphoneos-version-min=8.0 -isysroot $(xcrun -sdk ${SDK} --show-sdk-path)"
CHOST="arm-apple-darwin"
PREFIX="${HOME}/DEVICE_ARM"
dobuild

SDK="iphoneos"
ARCH_FLAGS="-arch arm64"
HOST_FLAGS="${ARCH_FLAGS} -miphoneos-version-min=8.0 -isysroot $(xcrun -sdk ${SDK} --show-sdk-path)"
CHOST="arm-apple-darwin"
PREFIX="${HOME}/DEVICE_ARM64"
dobuild

SDK="iphonesimulator"
ARCH_FLAGS="-arch i386"
HOST_FLAGS="${ARCH_FLAGS} -mios-simulator-version-min=8.0 -isysroot $(xcrun -sdk ${SDK} --show-sdk-path)"
CHOST="i386-apple-darwin"
PREFIX="${HOME}/SIM_i386"
dobuild

SDK="iphonesimulator"
ARCH_FLAGS="-arch x86_64"
HOST_FLAGS="${ARCH_FLAGS} -mios-simulator-version-min=8.0 -isysroot $(xcrun -sdk ${SDK} --show-sdk-path)"
CHOST="x86_64-apple-darwin"
PREFIX="${HOME}/SIM_x86_64"
dobuild

我只是将那个脚本放在一起,并验证它对 pixman 有效(添加了 --disable-libpng 和跳过测试).您可能需要为 libgcrypt 自定义它,但它用于显示为 iOS 构建基于 autoconf/automake/glibtool 的项目的一般模式.

I just threw that script together and verified it works (with the addition of --disable-libpng and skipping tests) for pixman. You will probably need to customize it for libgcrypt, but it serves to show the general pattern for building autoconf/automake/glibtool based projects for iOS.

构建后,您将在 ~/{DEVICE_ARM{,64},SIM_{i386,x86_64}} 中拥有内容,您可以将静态库放在一起,也可以在您的项目中使用它们(链接器将发出有关其他"档案丢失切片的警告,您可以忽略).

After building, you'll have content in ~/{DEVICE_ARM{,64},SIM_{i386,x86_64}} and you can either lipo the static libraries together or just use all of them in your project (the linker will emit warnings about missing slices for the "other" archives which you can ignore).

lipo -create -output lib.a DEVICE_ARM/lib/lib.a DEVICE_ARM64/lib/lib.a SIM_i386/lib/lib.a SIM_x86_64/lib/lib.a

这篇关于交叉编译为静态库 (libgcrypt) 以在 iOS 上使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆