Cross compile libgcrypt static lib for use in iOS

I downloaded the latest libgcrypt and 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; do; do the installation on my Mac (Mavericks w / OSX 10.10 and latest Xcode 6.1).

I can just connect to these new libraries from the OS X client application that I create. So far, so good. Just great. BUT, I also need to create an iOS client using the same source code.

Questions:

1) What are the changes in the sequence of building the command line for the library, will I need to create a universal static library for (simulator, Mac and iOS)? 2) Or do I need to create separate static libraries for iOS? And if so, again, what command-line magic would I need to get in order to get the target architecture correctly?

+5
source share
1 answer

Please note that it is not possible to create a universal library that will work for both iOS Simulator and macOS. iOS / Intel and macOS / Intel are not compatible with ABI over the C runtime library (Libc). This answer serves to show you how to cross-compile autoconf-based projects for iOS purposes, and you can easily merge the resulting static archives together.

You need 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 

I just threw this script together and checked that it works (with the addition of --disable-libpng and skipped tests) for pixman. You may have to configure it for libgcrypt, but it serves to display a common template for creating projects based on autoconf / automake / glibtool for iOS.

After creation, you will have content in ~ / {DEVICE_ARM {, 64}, SIM_ {i386, x86_64}}, and you can either lipo-static libraries together or just use them all in your project (the linker will emit warnings about missing slices for "other" archives that 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 
+12
source

Source: https://habr.com/ru/post/1206460/


All Articles