Mac上交叉编译iOS静态库

本文主要以fftw为例子,进行iOS静态库的编译。

环境要求:

➜  ~ xcodebuild -version
Xcode 9.4.1
Build version 9F2000

运行脚本如下:

#!/bin/sh

xcodebuild -version
xcodeversion_current=`xcodebuild -version`
xcodeversion="7.3.1"
result=$(echo $xcodeversion_current | grep "$xcodeversion")
echo $result
if [[ "$result" != "" ]]
then
  echo "此时Xcode版本设置错误,请运行命令 'sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer' 来更换Xcode版本 "
  exit
fi

# build for iOS / Mac
# changed by 10mitri
# original:
# http://stackoverflow.com/questions/3588904/how-to-link-third-party-libraries-like-fftw3-and-sndfile-to-an-iphone-project-in


# this is the folder where the libs will be generated
export OUTPUT_DIR=a_ios-libs

# Select toolchains folder
export XCODE_TOOLCHAINS=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain


#$(CURRENT_ARCH)

build_target()
{
    PLATFORM=$1
    ARCH=$2
    SDK_VERSION=$3
    CONFIGURE_HOST=$4
    IOS_DEPLOYMENT_TARGET=$5

    export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/$PLATFORM.platform/Developer/SDKs/$PLATFORM$SDK_VERSION.sdk

    export CPPFLAGS="-I$SDKROOT/usr/include/ -mfpu=neon"
    export CFLAGS="$CPPFLAGS -arch $ARCH -isysroot $SDKROOT -mfpu=neon -O3"
    export LD=$XCODE_TOOLCHAINS/usr/bin/ld
    export CXX="$XCODE_TOOLCHAINS/usr/bin/clang -arch $ARCH -fembed-bitcode -mfpu=neon"
    export CC="$XCODE_TOOLCHAINS/usr/bin/clang -arch $ARCH -fembed-bitcode -mfpu=neon"

    echo ---------------------------------------------------
    echo ---------------------------------------------------
    echo ---------------------------------------------------
    echo -------------- BUILD TARGET
    echo -------------- PLATFORM : $PLATFORM
    echo -------------- ARCH : $ARCH
    echo -------------- SDK_VERSION : $SDK_VERSION
    echo -------------- HOST : $CONFIGURE_HOST
    echo -------------- MIN iOS : $IOS_DEPLOYMENT_TARGET
    echo -------------- SDK PATH : $SDKROOT
    echo ---------------------------------------------------
    echo ---------------------------------------------------
    echo ---------------------------------------------------

    #sleep 3

    make clean

    ./configure --host=$CONFIGURE_HOST --enable-float  --enable-$ARCH-cntvct

    make -j4

    mkdir $OUTPUT_DIR/$ARCH

    # Copy the lib
    cp .libs/libfftw3f.a $OUTPUT_DIR/$ARCH/libfftw3f.a

    unset CPPFLAGS CFLAGS LD CXX CC
}


mkdir $OUTPUT_DIR

rm -rf $OUTPUT_DIR/*

# Copy the header file too, just for convenience
cp api/fftw3.h $OUTPUT_DIR/fftw3.h

#build_target "iPhoneOS" "armv7s" "11.4" "arm-apple-darwin" "7.0"
build_target "iPhoneOS" "armv7" "11.4" "arm-apple-darwin" "7.0"
build_target "iPhoneOS" "arm64" "11.4" "arm-apple-darwin" "7.0"
build_target "iPhoneSimulator" "x86_64" "11.4" "x86_64-apple-darwin" "7.0"
build_target "iPhoneSimulator" "i386" "11.4" "i386-apple-darwin" "7.0"

#build_target "MacOSX" "x86_64" "11.4" "i386-apple-darwin" "7.0"

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,039评论 3 119
  • 用到的组件 1、通过CocoaPods安装 2、第三方类库安装 3、第三方服务 友盟社会化分享组件 友盟用户反馈 ...
    SunnyLeong阅读 14,947评论 1 180
  • 电线划过天空给城市装点 路灯闪过行人给城市装点 路牌不分四季给城市装点 疾驰车子闪耀给城市装点 我希望着孤独是我的...
    eds陈明阅读 851评论 1 1
  • 有时候感动并不会流泪,有的只是流淌在心中的温暖。
    书洱阅读 2,256评论 2 0
  • 最近睡觉不规律,也许初夏还不太适应的原因,盖被子总是出汗,半夜醒来发现浑身被汗水浸透。盖被单有点凉,不小心容易感冒...
    陈讲运清洁能源阅读 2,350评论 1 2