How do I link third party libraries like fftw3 and sndfile to an iPhone project in Xcode?

前端 未结 9 1349
情歌与酒
情歌与酒 2020-12-09 07:08

I\'m trying to link third party libraries like fftw3 and sndfile to my iPhone project in Xcode3.2. I got it working in a regular Mac project by setting the \"Header Search P

9条回答
  •  忘掉有多难
    2020-12-09 07:52

    Build FFTW3 for iOS:

    Here is a script to create .h and .a files for different iOS architectures (device, simulator, ...)

    Enjoy it!

    #!/bin/sh
    
    # 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=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/"
    export CFLAGS="$CPPFLAGS -arch $ARCH -isysroot $SDKROOT"
    export LD=$XCODE_TOOLCHAINS/usr/bin/ld
    export CXX="$XCODE_TOOLCHAINS/usr/bin/clang -arch $ARCH -fembed-bitcode"
    export CC="$XCODE_TOOLCHAINS/usr/bin/clang -arch $ARCH -fembed-bitcode"
    
    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
    
    make -j4
    
    mkdir $OUTPUT_DIR/$ARCH
    
    # Copy the lib
    cp .libs/libfftw3.a $OUTPUT_DIR/$ARCH/libfftw3.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" "armv7" "10.2" "arm-apple-darwin" "9.0"
    build_target "iPhoneOS" "armv7s" "10.2" "arm-apple-darwin" "9.0"
    build_target "iPhoneOS" "arm64" "10.2" "arm-apple-darwin" "9.0"
    build_target "iPhoneSimulator" "x86_64" "10.2" "x86_64-apple-darwin" "9.0"
    build_target "iPhoneSimulator" "i386" "10.2" "i386-apple-darwin" "9.0"
    
    #build_target "MacOSX" "x86_64" "10.12" "i386-apple-darwin" "10.10"
    

提交回复
热议问题