2010-08-28 63 views
1

我想鏈接像fftw3和sndfile的第三方庫到Xcode3.2中的iPhone項目。我通過在項目構建配置下將「Header搜索路徑」設置爲「/ usr/local/include」和「其他鏈接程序標誌」設置爲「-lfftw3 -lsndfile」,從而在常規Mac項目中工作。但是,當我嘗試使用相同的設置在iPhone項目中構建它時,它給了我「-lfftw3找不到的庫」,退出代碼爲1的錯誤消息。如何將第三方庫如fftw3和sndfile鏈接到Xcode中的iPhone項目?

蘋果是否不允許在iPhone上使用?有沒有辦法解決這個問題?

回答

2

您需要將庫構建爲通用靜態庫。這個過程從圖書館到圖書館各不相同,但一般都是這樣的。

  1. 生成庫爲不同的平臺靜態庫(ARMv6及在至少I386)
  2. 使用脂創建從上面
  3. 拖建個人靜態庫通用庫和下降的普遍LIB到您的Xcode項目
  4. 拖頭文件拖放到你的Xcode項目

第一步一般是最棘手的,因爲許多圖書館有不同的構建過程。通常通過設置正確的編譯器標誌來使用iphone sdk而不是系統範圍的編譯器來完成。

1

這不是說Apple不允許該庫,而是因爲您鏈接到的版本是x86,所以它不會在iPhone上運行。您需要使用iPhone SDK構建庫,然後鏈接到該版本。

另外,你可以有點淘氣,並在你的主項目中包含第三方來源。頑皮,但它會證明蘋果沒有阻止你,並顯示圖書館是否會在電話上運行OK。

儘管將代碼保存在單獨構建的庫項目中,但它更加清潔。

5

對於編譯用fftw3在iOS的項目,我已經適應了這裏的腳本貼: http://robertcarlsen.net/2009/07/15/cross-compiling-for-iphone-dev-884

使用的OS X 10.6 fftw3.2.2與iOS SDK 3.2

#!/bin/sh 

# build_iphone.sh 
# build an arm/i386 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 


# make sure we start out clean 
make distclean 

# this is the folder where the results of our efforts will end up: 
export RESULT_DIR=ios-library 

# Select the desired iPhone SDK 
export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer 
export SDKROOT=$DEVROOT/SDKs/iPhoneOS3.2.sdk 

# Set up relevant environment variables 
export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.0.1/include/ -I$SDKROOT/usr/include/ -miphoneos-version-min=2.2" 
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT" 
export CPP="$DEVROOT/usr/bin/cpp $CPPFLAGS" 
export CXXFLAGS="$CFLAGS" 

# TODO: add custom flags as necessary for package 
./configure CC=$DEVROOT/usr/bin/arm-apple-darwin10-gcc-4.0.1 LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin 

make -j4 

# Copy the ARM library to a temporary location 
mkdir $RESULT_DIR 
cp .libs/libfftw3.a $RESULT_DIR/libfftw3_arm.a 

# Copy the header file too, just for convenience 
cp api/fftw3.h ios-library/fftw3.h 

# Do it all again for i386 
make distclean 

# Restore default environment variables 
unset CPPFLAGS CFLAGS CPP LDFLAGS CXXFLAGS DEVROOT SDKROOT 

export DEVROOT=/Developer 
export SDKROOT=$DEVROOT/SDKs/MacOSX10.6.sdk 

export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/i686-apple-darwin10/4.0.1/include/ -I$SDKROOT/usr/include/ -mmacosx-version-min=10.5" 
export CFLAGS="$CPPFLAGS -pipe -no-cpp-precomp -isysroot $SDKROOT -arch i386" 
export CPP="$DEVROOT/usr/bin/cpp $CPPFLAGS" 
export CXXFLAGS="$CFLAGS" 

# TODO: error checking 
./configure 
make -j4 

# Copy the native library to the temporary location 
cp .libs/libfftw3.a $RESULT_DIR/libfftw3_386.a 

# Create fat lib by combining the two versions 
lipo -arch arm $RESULT_DIR/libfftw3_arm.a -arch i386 $RESULT_DIR/libfftw3_386.a -create -output $RESULT_DIR/libfftw3.a 

# Remove intermediate binaries 
rm $RESULT_DIR/libfftw3_arm.a 
rm $RESULT_DIR/libfftw3_386.a 

# Unset used environment variables 
unset CPPFLAGS CFLAGS CPP LDFLAGS CPP CXXFLAGS DEVROOT SDKROOT 

運行這個腳本來自包含fftw3的目錄。你需要的文件應該放在ios-library文件夾中。

+0

嗨,我在編譯OSX 10.7時無法讓此腳本適用於ios5。這個腳本是否有更新的版本?我正在做的事似乎正在工作......謝謝。 – 2012-05-22 02:06:38

+0

我對iOS7/OSX 10.9有大部分的警告/libbench2/libbench2.a:5:255:警告:null字符被忽略[-Wnull-character]和ERRORS像../libbench2/libbench2.a:4:8 :錯誤:源文件無效UTF-8 – loretoparisi 2013-11-07 16:33:35

6

我修改Epskampie的腳本IOS 5.0以上
使用fftw3.3.3在OS X 10.7與IOS SDK 6.0和MacOSX的SDK 10.8

#!/bin/sh 

# build_ios5.sh 
# build an arm/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 Nickun 
# original: 
# http://stackoverflow.com/questions/3588904/how-to-link-third-party-libraries-like-fftw3-and-sndfile-to-an-iphone-project-in 


# make sure we start out clean 
make distclean 

# this is the folder where the results of our efforts will end up: 
export RESULT_DIR=ios-library 

# Select toolchains folder 
export XCODE_TOOLCHAINS=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain 
# Select the desired iPhone SDK 
export DEVROOT_IOS=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer 
export SDKROOT_IOS=$DEVROOT_IOS/SDKs/iPhoneOS6.0.sdk 
# Select the OSX SDK 
export DEVROOT_OSX=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer 
export SDKROOT_OSX=$DEVROOT_OSX/SDKs/MacOSX10.8.sdk 

# ------------------------ armv7--------------------------- 
# 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 --host=arm-apple-darwin --enable-float --enable-neon 

make -j2 

# Copy the ARM library to a temporary location 
mkdir $RESULT_DIR 
cp .libs/libfftw3f.a $RESULT_DIR/libfftw3f_armv7.a 

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

# ------------------------ armv7s--------------------------- 
# Do it all again for i386 
make distclean 

# 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 --host=arm-apple-darwin --enable-float --enable-neon 

make -j2 

# Copy the ARM library to a temporary location 
mkdir $RESULT_DIR 
cp .libs/libfftw3f.a $RESULT_DIR/libfftw3f_armv7s.a 


# ------------------------ i386 --------------------------- 
# Do it all again for i386 
make distclean 

# Restore default environment variables 
unset CPPFLAGS CFLAGS CPP LD CXX LDFLAGS CXXFLAGS 

export CPPFLAGS="-I$SDKROOT_OSX/usr/include/" 
export CFLAGS="$CPPFLAGS -arch i386 -no-cpp-precomp -mmacosx-version-min=10.7 -isysroot $SDKROOT_OSX" 
export LD="$XCODE_TOOLCHAINS/usr/bin/ld" 
export CXX="$XCODE_TOOLCHAINS/usr/bin/clang -x c++ -arch i386 -std=gnu++11 -stdlib=libc++" 
export CC="$XCODE_TOOLCHAINS/usr/bin/clang -x c -arch i386 -std=gnu99" 
export CXXFLAGS="$CFLAGS" 

# TODO: error checking 
./configure --enable-float 
make -j2 

# Copy the FAT native library to the temporary location 
cp .libs/libfftw3f.a $RESULT_DIR/libfftw3f_i386.a 

# ------------------------ x86_64 --------------------------- 
# Do it all again for x86_64 
make distclean 

# Restore default environment variables 
unset CPPFLAGS CFLAGS CPP LD CXX LDFLAGS CXXFLAGS 

export CPPFLAGS="-I$SDKROOT_OSX/usr/include/" 
export CFLAGS="$CPPFLAGS -arch x86_64 -no-cpp-precomp -mmacosx-version-min=10.7 -isysroot $SDKROOT_OSX" 
export LD="$XCODE_TOOLCHAINS/usr/bin/ld" 
export CXX="$XCODE_TOOLCHAINS/usr/bin/clang -x c++ -arch x86_64 -std=gnu++11 -stdlib=libc++" 
export CC="$XCODE_TOOLCHAINS/usr/bin/clang -x c -arch x86_64 -std=gnu99" 
export CXXFLAGS="$CFLAGS" 

# TODO: error checking 
./configure --enable-float 
make -j2 

# Copy the FAT native library to the temporary location 
cp .libs/libfftw3f.a $RESULT_DIR/libfftw3f_x86_64.a 



# Create fat lib by combining the two versions 
lipo -arch armv7 $RESULT_DIR/libfftw3f_armv7.a -arch armv7s $RESULT_DIR/libfftw3f_armv7s.a -arch i386 $RESULT_DIR/libfftw3f_i386.a -arch x86_64 $RESULT_DIR/libfftw3f_x86_64.a -create -output $RESULT_DIR/libfftw3f.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 
+0

libtool:link:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -xc -arch x86_64 -std = gnu99 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/-arch x86_64 -no-cpp-precomp -mmacosx-version -min = 10.7 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -o bench bench-bench.o bench-hook.o bench-fftw-bench.o ../.libs /libfftw3f.a ../libbench2/libbench2.a -lm bench-bench.o:1:1:錯誤:源文件無效UTF-8 – loretoparisi 2013-10-21 16:32:39

2

我修改Nickun的劇本爲Mac OS X 10.9。 2,iOS 7.1,fftw-3.3.4。它還爲fat文件添加了一個arm64切片。這裏是腳本 - >

#!/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 Adam 
# original: by Nickun 
# 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 results of our efforts will end up: 
export RESULT_DIR=ios-library 

# Select toolchains folder 
export XCODE_TOOLCHAINS=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain 
# Select the desired iPhone SDK 
export DEVROOT_IOS=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer 
export SDKROOT_IOS=$DEVROOT_IOS/SDKs/iPhoneOS7.1.sdk 
# Select the OSX SDK 
export DEVROOT_OSX=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer 
export SDKROOT_OSX=$DEVROOT_OSX/SDKs/MacOSX10.9.2.sdk 

# ------------------------ 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 $RESULT_DIR 
cp .libs/libfftw3f.a $RESULT_DIR/libfftw3f_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/libfftw3f.a $RESULT_DIR/libfftw3f_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 --host=arm-apple-darwin --target=arm-apple-darwin --enable-float --enable-neon 

make -j2 

cp .libs/libfftw3f.a $RESULT_DIR/libfftw3f_armv7.a 

# Copy the header file too, just for convenience 
cp 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 --host=arm-apple-darwin --target=arm-apple-darwin --enable-float --enable-neon 

make -j2 

# Copy the ARM library to a temporary location 
cp .libs/libfftw3f.a $RESULT_DIR/libfftw3f_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 --host=arm-apple-darwin --target=arm-apple-darwin --enable-float --enable-neon 

make -j2 

# Copy the ARM library to a temporary location 
cp .libs/libfftw3f.a ios-library/libfftw3f_arm64.a 


# Create fat lib by combining the two versions 
lipo -arch armv7 $RESULT_DIR/libfftw3f_armv7.a -arch armv7s $RESULT_DIR/libfftw3f_armv7s.a -arch i386 $RESULT_DIR/libfftw3f_i386.a -arch x86_64 $RESULT_DIR/libfftw3f_x86_64.a -arch arm64 $RESULT_DIR/libfftw3f_arm64.a -create -output $RESULT_DIR/libfftw3f.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 
+1

我想爲此添加一些註釋,運行腳本的麻煩,fi首先,您需要在運行腳本的相同目錄中創建目錄ios-library。該腳本不會自動創建它。你也應該使用gnu編譯器'gcc'。如果您在配置時遇到問題,請嘗試將您的環境變量CC設置爲'gcc'。 – 2014-04-28 16:37:32

0

我試圖亞當·弗里曼的腳本,它的真棒,但我不得不做以下,使其工作, 所以我在這裏分享我的發現。我的目標是使FFTW基於ARM庫,所以我可以建立它++通過Xcode的LIB與ARM架構

我也碰上通過loretoparisi

/libbench2/libbench2.a:5:255: warning: null character ignored [-Wnull-character] 
./libbench2/libbench2.a:4:8: error: source file is not valid UTF-8 

張貼的解決辦法是剝去廠名規則問題「測試」,「工具」文件夾和任何fftw-「智慧」相關的東西在Makefile.in和Makefile.am,我不知道這兩個文件夾中的文件有多重要,但我必須刪除它們,所以fftw構建可以成功沒有UTF-8錯誤

我也要修改腳本(我帶着醒着的霓虹燈和浮動精度標誌,再次我也不知道如何imp ortant是那些標誌)

#!/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 Adam 
# original: by Nickun 
# 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 results of our efforts will end up: 
export RESULT_DIR=ios-library 

# Select toolchains folder 
export XCODE_TOOLCHAINS=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain 
# Select the desired iPhone SDK 
export DEVROOT_IOS=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer 
export SDKROOT_IOS=$DEVROOT_IOS/SDKs/iPhoneOS7.1.sdk 
# Select the OSX SDK 
export DEVROOT_OSX=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer 
export SDKROOT_OSX=$DEVROOT_OSX/SDKs/MacOSX10.9.2.sdk 

# ------------------------ i386 --------------------------- 
# Do it for i386 
make clean 

# Restore default environment variables 
unset CPPFLAGS CFLAGS CPP CC LD CXX LDFLAGS CXXFLAGS 

export CFLAGS="-arch i386" 

# TODO: error checking 
./configure --host=i386-apple-darwin9.2.0 --target=i386-apple-darwin9.2.0 
make -j2 

# Copy the FAT native library to a temporary location 
mkdir $RESULT_DIR 
cp .libs/libfftw3.a $RESULT_DIR/libfftw3_i386.a 
rm -fr .libs/libfftw3.a 

# ------------------------ x86_64 --------------------------- 
# Do it all again for x86_64 
make clean 

# Restore default environment variables 
unset CPPFLAGS CFLAGS CPP CC LD CXX LDFLAGS CXXFLAGS 

# TODO: error checking 
./configure 
make -j2 

# Copy the FAT native library to the temporary location 
cp .libs/libfftw3.a $RESULT_DIR/libfftw3_x86_64.a 
rm -fr .libs/libfftw3.a 

# ------------------------ armv7--------------------------- 
# Do it all again for armv7 
make clean 

# Restore default environment variables 
unset CPPFLAGS CFLAGS CPP LD CXX CC LDFLAGS CXXFLAGS 

# Set up relevant environment variables 
export CPPFLAGS="-I$SDKROOT_IOS/usr/include/ " 
export CFLAGS="$CPPFLAGS -arch armv7 -no-cpp-precomp -miphoneos-version-min=6.1 -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++ " 
export CC="$XCODE_TOOLCHAINS/usr/bin/clang -x c -arch armv7 -std=gnu99 " 
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 --host=arm-apple-darwin --target=arm-apple-darwin 

make -j2 

cp .libs/libfftw3.a $RESULT_DIR/libfftw3_armv7.a 
rm -fr .libs/libfftw3.a 

# Copy the header file too, just for convenience 
cp 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 CC LDFLAGS CXXFLAGS 

# Set up relevant environment variables 
export CPPFLAGS="-I$SDKROOT_IOS/usr/include/ " 
export CFLAGS="$CPPFLAGS -arch armv7s -no-cpp-precomp -miphoneos-version-min=6.1 -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++ " 
export CC="$XCODE_TOOLCHAINS/usr/bin/clang -x c -arch armv7s -std=gnu99 " 
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 --host=arm-apple-darwin --target=arm-apple-darwin 

make -j2 

# Copy the ARM library to a temporary location 
cp .libs/libfftw3.a $RESULT_DIR/libfftw3_armv7s.a 
rm -fr .libs/libfftw3.a 

# ------------------------ arm64 --------------------------- 
# Do it all again for arm64 
make clean 

# Restore default environment variables 
unset CPPFLAGS CFLAGS CPP LD CXX CC LDFLAGS CXXFLAGS 

# Set up relevant environment variables 
export CPPFLAGS="-I$SDKROOT_IOS/usr/include/ " 
export CFLAGS="$CPPFLAGS -arch arm64 -no-cpp-precomp -miphoneos-version-min=6.1 -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++ " 
export CC="$XCODE_TOOLCHAINS/usr/bin/clang -x c -arch arm64 -std=gnu99 " 
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 --host=arm-apple-darwin --target=arm-apple-darwin 

make -j2 

# Copy the ARM library to a temporary location 
cp .libs/libfftw3.a ios-library/libfftw3_arm64.a 
rm -fr .libs/libfftw3.a 

# Create fat lib by combining the two versions 
lipo -arch armv7 $RESULT_DIR/libfftw3_armv7.a -arch armv7s $RESULT_DIR/libfftw3_armv7s.a -arch i386 $RESULT_DIR/libfftw3_i386.a -arch x86_64 $RESULT_DIR/libfftw3_x86_64.a -arch arm64 $RESULT_DIR/libfftw3_arm64.a -create -output $RESULT_DIR/libfftw3.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 CC CXX CXXFLAGS 
0

我已經適應以前的腳本

工作,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 

與@Ninji根據您必須修改Makefile.am

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

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/[email protected][email protected] -o [email protected] $(WISDOM_FLAGS) 
< 
< install-wisdom: wisdom 
< $(mkinstalldirs) $(WISDOM_DIR) 
< $(INSTALL_DATA) wisdom $(WISDOM_DIR)/$(WISDOM) 
1

爲iOS構建FFTW3:

下面是一個腳本來創建h和.a文件針對不同的iOS架構(器件,模擬器,...)

享受吧!

#!/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" 
+0

您節省了我的一天,謝謝! :D – user1573607 2017-09-22 16:40:08

+0

不客氣:-) – 10mitri 2017-09-29 12:29:18

相關問題