iOS 开发-编译第三方库 openssl及curl

1、前提

  • iOS编译库需要三个架构,arm64,arm64e,x86_64,其中x86_64为模拟器所需
  • iOS编译库需要下载xcode及对应的command line tool(执行命令时可以自动下载),下载失败需要去官网搜索下载

2、openssl

复制代码
  ./Configure iphoneos-cross --prefix=/Users/xxx/openssl-1.1.1b/openssl_armv7
  • 修改makefile以下项目:
    1. 真机(arm64为例,arm64e修改其中arm64为arm64e一致) # sdk上层路径

      CROSS_TOP=/Users/relly/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer

      sdk文件

      CROSS_SDK=iPhoneOS12.1.sdk

      CROSS_COMPILE=

      CC=/Users/relly/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch arm64

      CXX=

      CPPFLAGS=

      CFLAGS=-DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSLDIR="\"(OPENSSLDIR)\\"" -DENGINESDIR="\\"(ENGINESDIR)\"" -O3 -D_REENTRANT -isysroot (CROSS_TOP)/SDKs/(CROSS_SDK) -fno-common

    2. 模拟器 # sdk上层路径

      CROSS_TOP=/Users/relly/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer

      sdk文件

      CROSS_SDK=iPhoneSimulator12.1.sdk

      CROSS_COMPILE=

      CC=/Users/relly/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64

      CXX=

      CPPFLAGS=

      CFLAGS=-DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSLDIR="\"(OPENSSLDIR)\\"" -DENGINESDIR="\\"(ENGINESDIR)\"" -O3 -D_REENTRANT -isysroot (CROSS_TOP)/SDKs/(CROSS_SDK) -fno-common

  • 执行合并库命令
    1. lipo -create ../openssl_arm64/lib/libcrypto.a ../openssl_arm64e/lib/libcrypto.a ../openssl_x86_64/lib/libcrypto.a -output ./libcrypto.a

    2. lipo -create ../openssl_arm64/lib/libssl.a ../openssl_arm64e/lib/libssl.a ../openssl_x86_64/lib/libssl.a -output ./libssl.a

3、curl

  • 修改此脚本中的路径为openssl所编译路径后,赋予执行权限执行即可:

    #!/bin/sh

    make distclean

    CONFIGURE_FLAGS="--disable-shared --disable-frontend"

    ARCHS="arm64 arm64e x86_64"

    directories

    SOURCE是下载的第三方库源码包,解压后的目录,可以把sh脚本放到这个目录,source改为""

    SOURCE=""

    FAT是所有指令集build后,输出的目录,所有静态库被合并成一个静态库

    FAT="fat-libtool"

    SCRATCH是下载源码包,解压后的目录

    SCRATCH="./"

    must be an absolute path

    THIN 各自指令集build后输出的静态库所在的目录,每个指令集为一个静态库

    THIN=pwd/"thin-libtool"

    COMPILE="y"
    LIPO="y"

    if [ "*" ] then if [ "*" = "lipo" ]
    then

    skip compile

    COMPILE=
    else
    ARCHS="*" if [ # -eq 1 ]
    then

    skip lipo

    LIPO=
    fi
    fi
    fi

    if [ "COMPILE" ] then CWD=`pwd` echo "CWD/SOURCE........." for ARCH in ARCHS
    do
    echo "building ARCH..." mkdir -p "SCRATCH/ARCH" cd "SCRATCH/$ARCH"

    if [ "ARCH" = "i386" -o "ARCH" = "x86_64" ]
    then
    PLATFORM="iPhoneSimulator"
    if [ "$ARCH" = "x86_64" ]
    then
    SIMULATOR="-mios-simulator-version-min=7.0"
    HOST=x86_64-apple-darwin
    else
    SIMULATOR="-mios-simulator-version-min=5.0"
    HOST=i386-apple-darwin
    fi
    else
    PLATFORM="iPhoneOS"
    SIMULATOR=
    HOST=arm-apple-darwin
    fi

    XCRUN_SDK=echo $PLATFORM | tr '[:upper:]' '[:lower:]'
    CC="xcrun -sdk XCRUN_SDK clang -arch ARCH"
    #AS="CWD/SOURCE/extras/gas-preprocessor.pl CC" CFLAGS="-stdlib=libc++ -static -arch ARCH SIMULATOR" CXXFLAGS="CFLAGS"
    LDFLAGS="$CFLAGS"

    if [ "$ARCH" = "arm64" ]
    then
    echo 11
    SSL_PATH="--with-openssl=/Users/relly/Lib/IOS/openssl-1.1.1t-modified/build/openssl_arm64"
    fi

    if [ "$ARCH" = "arm64e" ]
    then
    echo 22
    SSL_PATH="--with-openssl=/Users/relly/Lib/IOS/openssl-1.1.1t-modified/build/openssl_arm64e"
    fi

    if [ "$ARCH" = "x86_64" ]
    then
    echo 33
    SSL_PATH="--with-openssl=/Users/relly/Lib/IOS/openssl-1.1.1t-modified/build/openssl_x86_64"
    fi

    echo SSL_PATH echo " ARCH ------------------------- $SSL_PATH"

    CC=CC CWD/SOURCE/configure SSL_PATH --disable-ldap
    CONFIGURE_FLAGS \ --host=HOST
    --prefix="THIN/ARCH"
    CC="CC" CFLAGS="CFLAGS" LDFLAGS="$LDFLAGS"

    make -j3 install
    cd $CWD
    done
    fi

    if [ "LIPO" ] then echo "building fat binaries..." mkdir -p FAT/lib
    set - ARCHS CWD=`pwd` cd THIN/1/lib for LIB in *.a do cd CWD
    lipo -create find $THIN -name $LIB -output FAT/lib/LIB
    done

    cd CWD cp -rf THIN/1/include FAT
    fi

  • 若出现compiler cannot create executables,执行命令指定xcode路径
    sudo xcode-select --switch /Users/relly/Downloads/Xcode.app/Contents/Developer/

相关推荐
吴Wu涛涛涛涛涛Tao14 小时前
基于TCA构建Instagram克隆:SwiftUI状态管理的艺术
ios·swiftui
2501_915921432 天前
iOS 应用上架多环境实战,Windows、Linux 与 Mac 的不同路径
android·ios·小程序·https·uni-app·iphone·webview
Cyclic10012 天前
IOS购买订阅通知信息解析说明Java
java·开发语言·ios
00后程序员张2 天前
iOS 应用上架常见问题与解决方案,多工具组合的实战经验
android·ios·小程序·https·uni-app·iphone·webview
2501_916007472 天前
iOS App 上架实战 从内测到应用商店发布的全周期流程解析
android·ios·小程序·https·uni-app·iphone·webview
wjm0410063 天前
ios八股文 -- Objective-c
开发语言·ios·objective-c
麦兜*3 天前
Swift + Xcode 开发环境搭建终极指南
开发语言·ios·swiftui·xcode·swift·苹果vision pro·swift5.6.3
Digitally3 天前
重置iPhone会删除所有内容吗? 详细回答
ios·iphone
普罗米拉稀4 天前
Flutter 复用艺术:Mixin 与 Abstract 的架构哲学与线性化解密
flutter·ios·面试
kymjs张涛4 天前
零一开源|前沿技术周刊 #12
ios·google·github