1、配置Android NDK編譯工具。
以下下載地址,直接放到瀏覽器中下載,不需要VPN
linux 32 bit
http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86.bin
linux 64 bit
http://dl.google.com/android/ndk/android-ndk-r10d-linux-x86_64.bin
Windows 32 bit
http://dl.google.com/android/ndk/android-ndk-r10d-windows-x86.exe
64 bit
http://dl.google.com/android/ndk/android-ndk-r10d-windows-x86_64.exe
Mac OS X 32 bit
http://dl.google.com/android/ndk/android-ndk-r10d-darwin-x86.bin
64 bit
http://dl.google.com/android/ndk/android-ndk-r10d-darwin-x86_64.bin
安裝方法:
請確保你已安裝了Android SDK
Linux 與Mac OS X (Darwin):
打開終端,進入到你下載包所在的目錄
執行chmod a+x 下載包名, 使其可執行,然后執行安裝包就行
比如:
ndk$ chmod a+x android-ndk-r10c-darwin-x86_64.bin
ndk$ ./android-ndk-r10c-darwin-x86_64.bin
windows安裝相對容易,直接雙擊安裝包
假設解壓出來的目錄在/usr/local/android-ndk-r10下
配置環境變量:
export NDK=/usr/local/android-ndk-r10
export PATH=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin:$PATH
2、下載Openblas源代碼:
下載路徑:https://sourceforge.net/projects/openblas/files/
下載源代碼版本:openblas_0.2.18.orig.tar.gz 和 openblas_0.2.18-1.dsc
將壓縮代碼文件解壓到目標路徑。
3、編譯Openblas的Android庫文件。
編譯指導:
https://github.com/xianyi/OpenBLAS/wiki/How-to-build-OpenBLAS-for-Android
a. 打開終端
b. 設置環境變量:
export SYSROOT=\$NDK/platforms/android-19/arch-arm
export CC="$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot=$SYSROOT"
c. 執行編譯命令:
make TARGET=ARMV7 HOSTCC=gcc CC=arm-linux-androideabi-gcc NOFORTRAN=1
d. 編譯問題:
sys/cdefs.h頭文件找不到問題。
In file included from getarch.c:80:0:
/usr/local/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.8/include-fixed/stdio.h:50:23: fatal error: sys/cdefs.h: No such file or directory
#include <sys/cdefs.h>
DIT re: the latest question revision:
The real question is - why is the compiler looking for header files under toolchains\arm-linux-androideabi-4.6\prebuilt\windows\lib\gcc\arm-linux-androideabi\4.6.x-google\include-fixed, when they are really at platforms\android-9\arch-arm\usr\include? Is there a rogue -I option somewhere? The include folder under toolchains, that the OP is having trouble with, looks crippled; it's probably an artifact of the GCC distribution. The real NDK header folder is elsewhere.
e. 修改文件路徑:
\interface\Makefile
\driver\level2\Makefile
\driver\level3\Makefile
\driver\others\Makefile
\kernel\Makefile
f. 修改內容:
override CFLAGS += -I/usr/local/android-ndk-r10/platforms/android-19/arch-arm/usr/include -I.
g. 繼續執行編譯
make TARGET=ARMV7 HOSTCC=gcc CC=arm-linux-androideabi-gcc NOFORTRAN=1
h. 執行完成,打包庫。
OpenBLAS build complete. (BLAS CBLAS)
OS ... Android
Architecture ... arm
BINARY ... 32bit
C compiler ... GCC (command line : arm-linux-androideabi-gcc)
Library Name ... libopenblas_armv7-r0.2.18.a (Single threaded)
To install the library, you can run "make PREFIX=/path/to/your/installation install".
執行命令打包庫文件。
make PREFIX=/home/zoufeng/openblas install
