Openblas编译Android NDK库的步骤

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

 

posted @ 2016-08-23 09:29  blue-fire  阅读(3916)  评论(0编辑  收藏  举报