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

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

问题描述

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

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 Simulator和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.

您将要执行以下操作:

#!/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

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

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