MXNet Amalgamation

This folder contains a amalgamation generation script to generate the entire mxnet library into one file. Currently it supports generation for predict API, which allows you to run prediction in platform independent way.

How to Generate the Amalgamation

Type make will generate the following files

    • The file you can used to compile predict API
  • ../lib/
    • The dynamic library generated for prediction.

You can also checkout the Makefile


The only dependency is a BLAS library.

Make sure to disable all other dependencies in the file.


This module is created by Jack Deng.


Setup NDK and build your standalone toolchain. Instructions Use the Advanced Method!!! In particular set PATH, CC and CXX. The minimum API level required is 16.


export PATH=/tmp/my-android-toolchain/bin:$PATH
export CC=arm-linux-androideabi-gcc   # or export CC=arm-linux-androideabi-clang
export CXX=arm-linux-androideabi-g++  # or export CXX=arm-linux-androideabi-clang++

Build OpenBLAS for Android: Build OpenBLAS Please put OpenBLAS source code outside mxnet directory. Modify OPENBLAS_ROOT in Makefile Type make ANDROID=1

In most cases you will want to use It contains the JNIs. In case you want to build your own JNI, link with libmxnet_predict.o

You can use generated library in Leliana WhatsThis Android app. Rename to and overwrite default library to use up-to-date mxnet version.


JS version uses emscripten to cross-compile the amalgamation source file into a Javascript library that can be integrated into client side applications. If you already have emanscripten installed then

make clean libmxnet_predict.js MIN=1

otherwise you can use emscripten docker image to compile in the following way

make clean libmxnet_predict.js MIN=1 EMCC="docker run -v ${PWD}:/src apiaryio/emcc emcc"

An example WebApp that uses the generated JS library can be found at mxnet.js


Chinese guide

Build OpenBlas for host machine Instructions Modify OPENBLAS_ROOT in Makefile. Type make If the build process is successful you will see the following output: ar rcs libmxnet_predict.a mxnet_predict-all.o


If present comment

#include <cblas.h>


#include <Accelerate/Accelerate.h>

Comment all occurrences of

#include <emmintrin.h>


#if defined(__ANDROID__) || defined(__MXNET_JS__)
#define MSHADOW_USE_SSE         0


#define MSHADOW_USE_SSE         0


#ifdef __GNUC__
  #define MX_TREAD_LOCAL __thread
#elif __STDC_VERSION__ >= 201112L
  #define  MX_TREAD_LOCAL _Thread_local
#elif defined(_MSC_VER)
  #define MX_TREAD_LOCAL __declspec(thread)


#define MX_TREAD_LOCAL __declspec(thread)

To build arm32 compatible version (e.g. iPhone 5):


typedef mxnet::common::ThreadLocalStore<ErrorEntry> MXAPIErrorStore;

const char *MXGetLastError() {
  return MXAPIErrorStore::Get()->last_error.c_str();

void MXAPISetLastError(const char* msg) {
  MXAPIErrorStore::Get()->last_error = msg;


//typedef mxnet::common::ThreadLocalStore<ErrorEntry> MXAPIErrorStore;

const char *MXGetLastError() {
  //return MXAPIErrorStore::Get()->last_error.c_str();
  return "";

void MXAPISetLastError(const char* msg) {
  //MXAPIErrorStore::Get()->last_error = msg;
  (void) msg;

You can use modified in PPPOE WhatsThis iOS app.