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

前端 未结 9 1300
情歌与酒
情歌与酒 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:46

    I've adapted previous scripts to

    WORK WITH XCODE7 iOS9.3 MACOSX 10.11 FFTW 3.3.4

    #!/bin/sh
    
    # build_lipo.sh
    # build an arm64 / armv7s / armv7 / i386 / x86_64 lib of fftw3
    # make sure to check that all the paths used in this script exist on your system
    #
    # adopted from:
    # http://robertcarlsen.net/2009/07/15/cross-compiling-for-iphone-dev-884
    # changed by garlix
    # original: by Nickun
    # http://stackoverflow.com/questions/3588904/how-to-link-third-party-libraries-like-fftw3-and-sndfile-to-an-iphone-project-in
    
    ######## EDIT HERE ############
    export iOS_SDK_VERSION=9.3
    export MACOSX_VERSION=10.11
    ###############################
    
    # this is the folder where the results of our efforts will end up:
    export RESULT_DIR=ios-library
    export XCODE_DEV_PATH=`xcode-select -print-path`
    # Select toolchains folder
    export XCODE_TOOLCHAINS=$XCODE_DEV_PATH/Toolchains/XcodeDefault.xctoolchain
    # Select the desired iPhone SDK
    export DEVROOT_IOS=$XCODE_DEV_PATH/Platforms/iPhoneOS.platform/Developer
    export SDKROOT_IOS=$DEVROOT_IOS/SDKs/iPhoneOS$iOS_SDK_VERSION.sdk
    # Select the OSX SDK
    export DEVROOT_OSX=$XCODE_DEV_PATH/Platforms/MacOSX.platform/Developer
    export SDKROOT_OSX=$DEVROOT_OSX/SDKs/MacOSX$MACOSX_VERSION.sdk
    
    export LIB_NAME=libfftw3f
    
    # ------------------------ i386 ---------------------------
    # Do it for i386
    make clean
    
    # Restore default environment variables
    unset CPPFLAGS CFLAGS CPP LD CXX LDFLAGS CXXFLAGS
    
    export CFLAGS="-arch i386"
    
    # TODO: error checking
    ./configure --enable-float --host=i386-apple-darwin9.2.0 --target=i386-apple-darwin9.2.0
    make -j2
    
    # Copy the FAT native library to a temporary location
    mkdir -p $RESULT_DIR
    cp .libs/$LIB_NAME.a $RESULT_DIR/$LIB_NAME\_i386.a
    
    # ------------------------ x86_64 ---------------------------
    # Do it all again for x86_64
    make clean
    
    # Restore default environment variables
    unset CPPFLAGS CFLAGS CPP LD CXX LDFLAGS CXXFLAGS
    
    # TODO: error checking
    ./configure --enable-float
    make -j2
    
    # Copy the FAT native library to the temporary location
    cp .libs/$LIB_NAME.a $RESULT_DIR/$LIB_NAME\_x86_64.a
    
    # ------------------------ armv7---------------------------
    # Do it all again for armv7
    make clean
    
    # Restore default environment variables
    unset CPPFLAGS CFLAGS CPP LD CXX LDFLAGS CXXFLAGS
    
    # Set up relevant environment variables
    export CPPFLAGS="-I$SDKROOT_IOS/usr/include/ -mfpu=neon"
    export CFLAGS="$CPPFLAGS -arch armv7 -mfpu=neon -no-cpp-precomp -miphoneos-version-min=5.0 -isysroot $SDKROOT_IOS"
    export LD=$XCODE_TOOLCHAINS/usr/bin/ld
    export CXX="$XCODE_TOOLCHAINS/usr/bin/clang -x c++ -arch armv7 -std=gnu++11 -stdlib=libc++ -mfpu=neon"
    export CC="$XCODE_TOOLCHAINS/usr/bin/clang -x c -arch armv7 -std=gnu99 -mfpu=neon"
    export CXXFLAGS="$CFLAGS"
    
    # TODO: add custom flags as necessary for package
    #  remove '--enable-float' for double precision
    #  and take a 'libfftw3.a' file instead
    ./configure --enable-float --enable-neon --host=arm-apple-darwin --target=arm-apple-darwin
    
    make -j2
    
    cp .libs/$LIB_NAME.a $RESULT_DIR/$LIB_NAME\_armv7.a
    
    # Copy the header file too, just for convenience
    cp dft/api/fftw3.h $RESULT_DIR/fftw3.h
    
    # ------------------------ armv7s---------------------------
    # Do it all again for i386
    make clean
    
    # Restore default environment variables
    unset CPPFLAGS CFLAGS CPP LD CXX LDFLAGS CXXFLAGS
    
    # Set up relevant environment variables
    export CPPFLAGS="-I$SDKROOT_IOS/usr/include/ -mfpu=neon"
    export CFLAGS="$CPPFLAGS -arch armv7s -mfpu=neon -no-cpp-precomp -miphoneos-version-min=5.0 -isysroot $SDKROOT_IOS"
    export LD=$XCODE_TOOLCHAINS/usr/bin/ld
    export CXX="$XCODE_TOOLCHAINS/usr/bin/clang -x c++ -arch armv7s -std=gnu++11 -stdlib=libc++ -mfpu=neon"
    export CC="$XCODE_TOOLCHAINS/usr/bin/clang -x c -arch armv7s -std=gnu99 -mfpu=neon"
    export CXXFLAGS="$CFLAGS"
    
    # TODO: add custom flags as necessary for package
    #  remove '--enable-float' for double precision
    #  and take a 'libfftw3.a' file instead
    ./configure --enable-float --enable-neon --host=arm-apple-darwin --target=arm-apple-darwin
    make -j2
    
    # Copy the ARM library to a temporary location
    cp .libs/$LIB_NAME.a $RESULT_DIR/$LIB_NAME\_armv7s.a
    
    # ------------------------ arm64 ---------------------------
    # Do it all again for arm64
    make clean
    
    # Restore default environment variables
    unset CPPFLAGS CFLAGS CPP LD CXX LDFLAGS CXXFLAGS
    
    # Set up relevant environment variables
    export CPPFLAGS="-I$SDKROOT_IOS/usr/include/ -mfpu=neon"
    export CFLAGS="$CPPFLAGS -arch arm64 -mfpu=neon -no-cpp-precomp -miphoneos-version-min=5.0 -isysroot $SDKROOT_IOS"
    export LD=$XCODE_TOOLCHAINS/usr/bin/ld
    export CXX="$XCODE_TOOLCHAINS/usr/bin/clang -x c++ -arch arm64 -std=gnu++11 -stdlib=libc++ -mfpu=neon"
    export CC="$XCODE_TOOLCHAINS/usr/bin/clang -x c -arch arm64 -std=gnu99 -mfpu=neon"
    export CXXFLAGS="$CFLAGS"
    
    # TODO: add custom flags as necessary for package
    #  remove '--enable-float' for double precision
    #  and take a 'libfftw3.a' file instead
    ./configure --enable-float --enable-neon --host=arm-apple-darwin --target=arm-apple-darwin
    
    make -j2
    
    # Copy the ARM library to a temporary location
    cp .libs/$LIB_NAME.a ios-library/$LIB_NAME\_arm64.a
    
    
    # Create fat lib by combining the two versions
    lipo -arch armv7 $RESULT_DIR/$LIB_NAME\_armv7.a -arch armv7s $RESULT_DIR/$LIB_NAME\_armv7s.a -arch i386 $RESULT_DIR/$LIB_NAME\_i386.a -arch x86_64 $RESULT_DIR/$LIB_NAME\_x86_64.a -arch arm64 $RESULT_DIR/$LIB_NAME\_arm64.a -create -output $RESULT_DIR/$LIB_NAME.a
    
    # Remove intermediate binaries
    #rm $RESULT_DIR/libfftw3_armv7.a
    #rm $RESULT_DIR/libfftw3_i386.a
    #rm $RESULT_DIR/libfftw3_x86_64.a
    
    # Unset used environment variables
    unset CPPFLAGS CFLAGS CPP LD LDFLAGS CXX CXXFLAGS
    

    According with @Ninji you have to modify Makefile.am

     34c34
     < libbench2 $(CHICKEN_EGG) tests mpi doc tools m4
     ---
     > libbench2 $(CHICKEN_EGG) mpi doc m4
     95,108c95
     < pkgconfig_DATA = fftw3@PREC_SUFFIX@.pc
     < 
     < WISDOM_DIR = /etc/fftw
     < WISDOM = wisdom@PREC_SUFFIX@
     < 
     < WISDOM_TIME=12 # default to 12-hour limit, i.e. overnight
     < WISDOM_FLAGS=--verbose --canonical --time-limit=$(WISDOM_TIME)
     < 
     < wisdom:
     <   tools/fftw@PREC_SUFFIX@-wisdom -o $@ $(WISDOM_FLAGS)
     < 
     < install-wisdom: wisdom
     <   $(mkinstalldirs) $(WISDOM_DIR)
     <   $(INSTALL_DATA) wisdom $(WISDOM_DIR)/$(WISDOM)
     ---
     > pkgconfig_DATA = fftw3@PREC_SUFFIX@.pc
     \ No newline at end of file
    

    and Makefile.in

    235c235
     <    libbench2 . threads tests mpi doc tools m4
     ---
     >    libbench2 . threads mpi doc m4
     447c447
     < libbench2 $(CHICKEN_EGG) tests mpi doc tools m4
     ---
     > libbench2 $(CHICKEN_EGG) mpi doc m4
     1053,1058d1052
     < wisdom:
     <    tools/fftw@PREC_SUFFIX@-wisdom -o $@ $(WISDOM_FLAGS)
     < 
     < install-wisdom: wisdom
     <    $(mkinstalldirs) $(WISDOM_DIR)
     <    $(INSTALL_DATA) wisdom $(WISDOM_DIR)/$(WISDOM)
    

提交回复
热议问题