Skip to content

How to build OpenBLAS for Android

Paul MUSTIÈRE edited this page Apr 26, 2016 · 30 revisions

Building OpenBLAS without LAPACK

The prebuilt Android NDK toolchains do not include Fortran, hence LAPACK cannot be built. You can still build OpenBLAS without it. For instructions on how to build OpenBLAS with LAPACK, 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 with:

# Add the toolchain to your path
export PATH=/path/to/standalone-toolchain/bin:$PATH

# Build without LAPACK for ARMV7
make TARGET=ARMV7 HOSTCC=gcc CC=arm-linux-androideabi-gcc NO_LAPACK=1
# Build without LAPACK for ARMV8
make TARGET=ARMV8 BINARY=64 HOSTCC=gcc CC=aarch64-linux-android-gcc NO_LAPACK=1

Building OpenBLAS with LAPACK

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:

# Add the toolchain to your path
export PATH=/path/to/standalone-toolchain-with-fortran/bin:$PATH

# Build with LAPACK for ARMV7
make TARGET=ARMV7 HOSTCC=gcc CC=arm-linux-androideabi-gcc
# Build with LAPACK for ARMV8
make TARGET=ARMV8 BINARY=64 HOSTCC=gcc CC=aarch64-linux-android-gcc

Linking OpenBLAS for ARMV7

If you are using ndk-build, you need to set the ABI to hard floating points in your Application.mk:

APP_ABI := armeabi-v7a-hard

This will set the appropriate flags for you. If you are not using ndk-build, you will want to add the following flags:

CFLAGS += -mhard-float -D_NDK_MATH_NO_SOFTFP=1
LDFLAGS += -Wl,--no-warn-mismatch -lm_hard