Prerequisites
Stack Exchange Network. Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange.
In addition to the Android NDK, you will need both Perl and a C compiler on the build host as these are currentlyrequired by the OpenBLAS build environment.
Building OpenBLAS without Fortran
see below for building with clang as required by recent ndks
The prebuilt Android NDK toolchains do not include Fortran, hence parts like LAPACK cannot be built. You can still build OpenBLAS without it. For instructions on how to build OpenBLAS with Fortran, see the next section.
To use easily the prebuilt toolchains, follow building a standalone toolchain for your desired architecture.This would be arm-linux-androideabi-gcc-4.9
for ARMV7 and aarch64-linux-android-gcc-4.9
for ARMV8.
You can build OpenBLAS (0.2.19 and earlier) with:
Since we are cross-compiling, we make the libs
recipe, not all
. Otherwise you will get errors when trying to link/run tests as versions up to and including 0.2.19 cannot build a shared library for Android.
From 0.2.20 on, you can MUST leave off the 'libs' to get a full build, and you may want to use the softfp ABI instead of the deprecated hardfp one on ARMV7 so you would use
If you get an error about stdio.h not being found, you need to specify your sysroot in the CFLAGS argument to make
likeCFLAGS=--sysroot=$NDK/platforms/android-16/arch-arm
When you are done, install OpenBLAS into the desired directory. Be sure to also use all command line optionshere that you specified for building, otherwise errors may occur as it tries to install things you did not build:
Building OpenBLAS with Fortran
Instructions on how to build the GNU toolchains with Fortran can be found here. The Releases section provides prebuilt versions, use the standalone one.
You can build OpenBLAS with:
As mentioned above you can leave off the libs
argument here when building 0.2.20 and later, and you may want to add ARM_SOFTFP_ABI=1 when building for ARMV7.
Linking OpenBLAS (0.2.19 and earlier) for ARMV7
If you are using ndk-build
, you need to set the ABI to hard floating points in your Application.mk:
This will set the appropriate flags for you. If you are not using ndk-build
, you will want to add the following flags:
From 0.2.20 on, it is also possible to build for the softfp ABI by specifying ARM_SOFTFP_ABI=1 during the build.In that case, also make sure that all your dependencies are compiled with -mfloat-abi=softfp as well, as mixing'hard' and 'soft' floating point ABIs in a program will make it crash.
Mac Blas Library Florida
Most recent Android NDKs stopped supporting gcc, so you would need to use clang to compile OpenBLAS. clang is supported from OpenBLAS 0.2.20 version onwards. See below sections on how to build with clang for ARMV7 and ARMV8 targets.Note that you still need to build a standalone toolchain first, following building a standalone toolchain for your desired architecture.If you want to use static linking, you need to choose an API level below 23 currently due to NDK bug 272(https://github.com/android-ndk/ndk/issues/272 , the libc.a lacks a definition of stderr) that will probablybe fixed in r17 of the NDK.
Build ARMV7 with clang
On a Mac, it may also be necessary to give the complete path to the ar
utility in the make command above, like so:
otherwise you may get a linker error complaining about a 'malformed archive header name at 8' when the native OSX ar command was invoked instead.
Build ARMV8 with clang
Mac Blas Library Hours
Note: Using TARGET=CORTEXA57 in place of ARMV8 will pick up better optimized routines. Implementations for CORTEXA57 target is compatible with all other armv8 targets.