编译-C语言库FFTW支持iOS平台的静态库

// 查看xcode 的版本
$:xcodebuild -version
Xcode 10.2.1
Build version 10E1001

FFTW:傅立叶变换常用库–fftw

FFTW官网:http://www.fftw.org/

下载下来fftw-3.3.8版本,并解压。
执行configure生成Makefile。
$:cd 到FFTW的根目录
$:./configure

后查看一下Makefile文件,找到
CC
CFLAGS
CPP
CPPFLAGS 的配置。

CC = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -fembed-bitcode -mfpu=neon
CFLAGS = -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.2.sdk/usr/include/ -mfpu=neon -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.2.sdk -mfpu=neon -O3
CPP = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -fembed-bitcode -mfpu=neon -E
CPPFLAGS = -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.2.sdk/usr/include/ -mfpu=neon

添加脚本并执行

脚本内容,脚本文件放到根目录下,./configure执行后,执行脚本
$:bash xxx.sh
等待漫长的编译过程。完成后。去a_ios-libs 文件夹下验证编译的静态库

#!/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" "12.2" "arm-apple-darwin" "7.0"
build_target "iPhoneOS" "armv7" "12.2" "arm-apple-darwin" "7.0"
build_target "iPhoneOS" "arm64" "12.2" "arm-apple-darwin" "7.0"
build_target "iPhoneSimulator" "x86_64" "12.2" "x86_64-apple-darwin" "7.0"
build_target "iPhoneSimulator" "i386" "12.2" "i386-apple-darwin" "7.0"

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

注意修改iOS SDK的版本我的12.2 。

报错解决

这个回答的脚本: Based on the answer by 10mitri, working for fftw-3.3.8, iOS SDK 12.2, XCode 10.2.

https://stackoverflow.com/questions/3588904/how-do-i-link-third-party-libraries-like-fftw3-and-sndfile-to-an-iphone-project

参考

Mac上交叉编译iOS静态库

发布了249 篇原创文章 · 获赞 224 · 访问量 20万+

猜你喜欢

转载自blog.csdn.net/shifang07/article/details/102579313