http://tungchingkai.blogspot.jp/2016/11/how-to-build-c-static-libraries-boost.html

How to build C++ static libraries (boost and QuantLib) for Android Studio

(1) Create standalone toolchain for Android in Mac

#create standalone toolchain for x86, x86_64, arm and arm64
#assume ndk is installed in Mac at ~/Library/Android/sdk/ndk-bundle
#API level will be set to the minimum supported level for the given architecture (currently 9 for 32-bit architectures and 21 for 64-bit architectures)
~/Library/Android/sdk/ndk-bundle/build/tools/make_standalone_toolchain.py --arch x86 --install-dir ~/Library/Android/sdk/ndk-bundle/sources/android-toolchain-x86
~/Library/Android/sdk/ndk-bundle/build/tools/make_standalone_toolchain.py --arch x86_64 --install-dir ~/Library/Android/sdk/ndk-bundle/sources/android-toolchain-x86_64
~/Library/Android/sdk/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm --install-dir ~/Library/Android/sdk/ndk-bundle/sources/android-toolchain-arm
~/Library/Android/sdk/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm64 --install-dir ~/Library/Android/sdk/ndk-bundle/sources/android-toolchain-arm64

linux:

/home/musictom/Android/Sdk/ndk-bundle/build/tools/make_standalone_toolchain.py --arch mips --install-dir /home/musictom/Android/Sdk/ndk-bundle/sources/android-toolchain-mips --api 24 --force

(2) Download and build boost for Android

# download boost source to ndk-bundle
cd ~/Library/Android/sdk/ndk-bundle/sources
curl -O http://ncu.dl.sourceforge.net/project/boost/boost/1.62.0/boost_1_62_0.tar.bz2
tar xjvf boost_1_62_0.tar.bz2
cd boost_1_62_0

# create the following user-config.jam at ~/Library/Android/sdk/ndk-bundle/sources/boost_1_62_0/tools/build/src/
cat > tools/build/src/user-config.jam << 'EOF'
# ------------------
# Android configurations.
# ------------------

import os ;
local NDK_ROOT = [ os.environ NDK_ROOT ] ;
# --------------------------------------------------------------------
local ANDROID_TOOLCHAIN_x86 = /sources/android-toolchain-x86 ;

using gcc : x86
:
$(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86)/bin/i686-linux-android-g++
:
<archiver>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86)/bin/i686-linux-android-ar
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-fpic
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-Wno-psabi
<compileflags>-Wno-missing-field-initializers
<compileflags>-no-canonical-prefixes
<linkflags>-no-canonical-prefixes
<compileflags>-Os
<compileflags>-fomit-frame-pointer
<compileflags>-fno-strict-aliasing
<compileflags>-funswitch-loops
<compileflags>-finline-limit=300
<compileflags>-Wa,--noexecstack
<compileflags>-DANDROID
<compileflags>-D__ANDROID__
<compileflags>-DNDEBUG
<compileflags>-O2
<compileflags>-g
<root>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86)/sysroot
# @Moss - Above are the 'official' android flags
<architecture>x86
<compileflags>-fvisibility=hidden
<compileflags>-fvisibility-inlines-hidden
<compileflags>-fdata-sections
<cxxflags>-D_REENTRANT
<cxxflags>-D_GLIBCXX__PTHREADS
<compileflags>-Wno-long-long
<compileflags>-Wno-missing-field-initializers
<compileflags>-Wno-unused-variable
;

# --------------------------------------------------------------------
local ANDROID_TOOLCHAIN_x86_64 = /sources/android-toolchain-x86_64 ;

using gcc : x86_64
:
$(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86_64)/bin/x86_64-linux-android-g++
:
<archiver>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86_64)/bin/x86_64-linux-android-ar
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-fpic
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-Wno-psabi
<compileflags>-Wno-missing-field-initializers
<compileflags>-no-canonical-prefixes
<linkflags>-no-canonical-prefixes
<compileflags>-Os
<compileflags>-fomit-frame-pointer
<compileflags>-fno-strict-aliasing
<compileflags>-funswitch-loops
<compileflags>-finline-limit=300
<compileflags>-Wa,--noexecstack
<compileflags>-DANDROID
<compileflags>-D__ANDROID__
<compileflags>-DNDEBUG
<compileflags>-O2
<compileflags>-g
<root>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86_64)/sysroot
# @Moss - Above are the 'official' android flags
<architecture>x86
<compileflags>-fvisibility=hidden
<compileflags>-fvisibility-inlines-hidden
<compileflags>-fdata-sections
<cxxflags>-D_REENTRANT
<cxxflags>-D_GLIBCXX__PTHREADS
<compileflags>-Wno-long-long
<compileflags>-Wno-missing-field-initializers
<compileflags>-Wno-unused-variable
;

# --------------------------------------------------------------------

local ANDROID_TOOLCHAIN_ARM = /sources/android-toolchain-arm ;
using gcc : armeabi
:
$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/bin/arm-linux-androideabi-g++
:
<archiver>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/bin/arm-linux-androideabi-ar
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-fpic
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-D__ARM_ARCH_5__
<compileflags>-D__ARM_ARCH_5T__
<compileflags>-D__ARM_ARCH_5E__
<compileflags>-D__ARM_ARCH_5TE__
<compileflags>-Wno-psabi
<compileflags>-march=armv5te
<compileflags>-mtune=xscale
<compileflags>-msoft-float
<compileflags>-mthumb
<linkflags>-march=armv5te
<compileflags>-Os
<compileflags>-fomit-frame-pointer
<compileflags>-fno-strict-aliasing
<compileflags>-finline-limit=64
<compileflags>-Wa,--noexecstack
<compileflags>-DANDROID
<compileflags>-D__ANDROID__
<compileflags>-DNDEBUG
<compileflags>-O2
<compileflags>-g
<root>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/sysroot
# @Moss - Above are the 'official' android flags
<architecture>arm
<compileflags>-fvisibility=hidden
<compileflags>-fvisibility-inlines-hidden
<compileflags>-fdata-sections
<cxxflags>-D_REENTRANT
<cxxflags>-D_GLIBCXX__PTHREADS
<compileflags>-Wno-long-long
<compileflags>-Wno-missing-field-initializers
<compileflags>-Wno-unused-variable
;

# --------------------------------------------------------------------
using gcc : armeabi_v7a
:
$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/bin/arm-linux-androideabi-g++
:
<archiver>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/bin/arm-linux-androideabi-ar
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-fpic
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-Wno-psabi
<compileflags>-march=armv7-a
<compileflags>-msoft-float
<compileflags>-mfpu=neon
<compileflags>-mthumb
<linkflags>-march=armv7-a
<linkflags>-Wl,--fix-cortex-a8
<compileflags>-Os
<compileflags>-fomit-frame-pointer
<compileflag>-fno-strict-aliasing
<compileflags>-finline-limit=64
<compileflags>-Wa,--noexecstack
<compileflags>-DANDROID
<compileflags>-D__ANDROID__
<compileflags>-DNDEBUG
<compileflags>-O2
<compileflags>-g
<root>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/sysroot
# @Moss - Above are the 'official' android flags
<architecture>arm
<compileflags>-fvisibility=hidden
<compileflags>-fvisibility-inlines-hidden
<compileflags>-fdata-sections
<cxxflags>-D__arm__
<cxxflags>-D_REENTRANT
<cxxflags>-D_GLIBCXX__PTHREADS
<compileflags>-Wno-long-long
<compileflags>-Wno-missing-field-initializers
<compileflags>-Wno-unused-variable
;

# --------------------------------------------------------------------
local ANDROID_TOOLCHAIN_ARM64 = /sources/android-toolchain-arm64 ;

using gcc : arm64_v8a
:
$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM64)/bin/aarch64-linux-android-g++
:
<archiver>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM64)/bin/aarch64-linux-android-ar
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-fpic
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-fstack-protector
<compileflags>-Wno-psabi
<compileflags>-march=armv8-a
<compileflags>-mtune=cortex-a53
<linkflags>-march=armv8-a
<compileflags>-Os
<compileflags>-fno-short-enums
<compileflags>-fomit-frame-pointer
<compileflags>-fno-strict-aliasing
<compileflags>-finline-limit=64
<compileflags>-DANDROID
<compileflags>-D__ANDROID__
<compileflags>-DNDEBUG
<compileflags>-O2
<compileflags>-g
<root>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM64)/sysroot
# @Moss - Above are the 'official' android flags
<architecture>arm
<compileflags>-fvisibility=hidden
<compileflags>-fvisibility-inlines-hidden
<compileflags>-fdata-sections
<cxxflags>-D_REENTRANT
<cxxflags>-D_GLIBCXX__PTHREADS
<compileflags>-Wno-long-long
<compileflags>-Wno-missing-field-initializers
<compileflags>-Wno-unused-variable
;

EOF

# bootstrap
./bootstrap.sh --with-libraries=atomic,chrono,date_time,exception,filesystem,graph,iostreams,math,program_options,random,regex,serialization,signals,system,test,thread,wave

# clean and build for Android, j option is num of cores x 1.5
rm -fr android-build
./b2 -j6 -sNDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" --build-dir=android-build --stagedir=android-build/x86 toolset=gcc-x86 threading=multi link=static stage
./b2 -j6 -sNDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" --build-dir=android-build --stagedir=android-build/x86_64 toolset=gcc-x86_64 threading=multi link=static stage
./b2 -j6 -sNDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" --build-dir=android-build --stagedir=android-build/armeabi toolset=gcc-armeabi threading=multi link=static stage
./b2 -j6 -sNDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" --build-dir=android-build --stagedir=android-build/armeabi-v7a toolset=gcc-armeabi_v7a threading=multi link=static stage
./b2 -j6 -sNDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" --build-dir=android-build --stagedir=android-build/arm64-v8a toolset=gcc-arm64_v8a threading=multi link=static stage

# create link for include folder
cd android-build
mkdir -p include
cd include
ln -s ../../boost .

(3) Create Android.mk at ~/Library/Android/sdk/ndk-bundle/sources/boost_1_62_0/ for ndkBuild in Android Studio

# create the following Android.mk
cat > ~/Library/Android/sdk/ndk-bundle/sources/boost_1_62_0/Android.mk << 'EOF'
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_atomic
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_atomic.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_chrono
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_chrono.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_date_time
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_date_time.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_exception
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_exception.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_filesystem
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_filesystem.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_graph
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_graph.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_iostreams
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_iostreams.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_math_c99
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_c99.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_math_c99f
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_c99f.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_math_c99l
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_c99l.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_math_tr1
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_tr1.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_math_tr1f
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_tr1f.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_math_tr1l
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_tr1l.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_prg_exec_monitor
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_prg_exec_monitor.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_program_options
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_program_options.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_random
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_random.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_regex
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_regex.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_serialization
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_serialization.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_signals
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_signals.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_system
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_system.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_test_exec_monitor
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_test_exec_monitor.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_thread
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_thread.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_timer
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_timer.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_unit_test_framework
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_unit_test_framework.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_wave
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_wave.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libboost_wserialization
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_wserialization.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)

EOF

(4) Download and build QuantLib for Android

# download quantlib source to ndk-bundle
cd ~/Library/Android/sdk/ndk-bundle/sources
curl -O http://nchc.dl.sourceforge.net/project/quantlib/QuantLib/1.9/QuantLib-1.9.tar.gz

tar xzvf QuantLib-1.9.tar.gz
cd QuantLib-1.9

#Create the following shell script for x86
cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/build-x86.sh << 'x86EOF'
#!/bin/bash
# build-x86.sh
BUILD_DIR=android-build
mkdir -p ${BUILD_DIR}
INSTALL_DIR="`pwd`/${BUILD_DIR}"
YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`"
NDK_DIR="${HOME}/Library/Android/sdk/ndk-bundle"
YOUR_PATH_TO_NDK="`cd "${NDK_DIR}";pwd`"
YOUR_TOOLCHAIN=${YOUR_PATH_TO_NDK}/sources/android-toolchain-x86
export CC=${YOUR_TOOLCHAIN}/bin/i686-linux-android-gcc
export CXX=${YOUR_TOOLCHAIN}/bin/i686-linux-android-g++
export CPP=${YOUR_TOOLCHAIN}/bin/i686-linux-android-cpp
export AR=${YOUR_TOOLCHAIN}/bin/i686-linux-android-ar
export RANLIB=${YOUR_TOOLCHAIN}/bin/i686-linux-android-ranlib
export LD=${YOUR_TOOLCHAIN}/bin/i686-linux-android-ld
export CPPFLAGS="-fexceptions -frtti -fpic -ffunction-sections -funwind-tables -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections"
export CXXFLAGS="-DANDROID -D__ANDROID__ -DNDEBUG -O2 -g -D_REENTRANT -D_GLIBCXX__PTHREADS"
sysroot=${YOUR_TOOLCHAIN}
boost_include="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/include";pwd`"
boost_lib="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/x86/lib";pwd`"

make distclean
./configure --prefix=/x86 --host=i686-linux-android --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --enable-examples=no --enable-thread-safe-observer-pattern
make -j6
make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR}

x86EOF

#Create the following shell script for x86_64
cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/build-x86_64.sh << 'x86_64EOF'

#!/bin/bash
# build-x86_64.sh
BUILD_DIR=android-build
mkdir -p ${BUILD_DIR}
INSTALL_DIR="`pwd`/${BUILD_DIR}"
YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`"
NDK_DIR="${HOME}/Library/Android/sdk/ndk-bundle"
YOUR_PATH_TO_NDK="`cd "${NDK_DIR}";pwd`"
YOUR_TOOLCHAIN=${YOUR_PATH_TO_NDK}/sources/android-toolchain-x86_64
export CC=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-gcc
export CXX=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-g++
export CPP=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-cpp
export AR=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-ar
export RANLIB=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-ranlib
export LD=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-ld
export CPPFLAGS="-fexceptions -frtti -fpic -ffunction-sections -funwind-tables -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections"
export CXXFLAGS="-D_REENTRANT -D_GLIBCXX__PTHREADS -DANDROID -D__ANDROID__ -DNDEBUG -O2 -g"
sysroot=${YOUR_TOOLCHAIN}
boost_include="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/include";pwd`"
boost_lib="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/x86_64/lib";pwd`"

make distclean
./configure --prefix=/x86_64 --host=x86_64-linux-android --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --enable-examples=no --enable-thread-safe-observer-pattern
make -j6
make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR}

x86_64EOF

#Create the following shell script for armeabi
cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/build-armeabi.sh << 'armeabiEOF'
#!/bin/bash
# build-armeabi.sh
BUILD_DIR=android-build
mkdir -p ${BUILD_DIR}
INSTALL_DIR="`pwd`/${BUILD_DIR}"
YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`"
NDK_DIR="${HOME}/Library/Android/sdk/ndk-bundle"
YOUR_PATH_TO_NDK="`cd "${NDK_DIR}";pwd`"
YOUR_TOOLCHAIN=${YOUR_PATH_TO_NDK}/sources/android-toolchain-arm
export CC=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-gcc
export CXX=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-g++
export CPP=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-cpp
export AR=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ar
export RANLIB=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ranlib
export LD=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ld
export CPPFLAGS="-fexceptions -frtti -fpic -ffunction-sections -funwind-tables -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections"
export CXXFLAGS="-D_REENTRANT -D_GLIBCXX__PTHREADS -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -march=armv5te -mtune=xscale -msoft-float -mthumb -DANDROID -D__ANDROID__ -DNDEBUG -O2 -g"
export LDFLAGS="-march=armv5te"
sysroot=${YOUR_TOOLCHAIN}
boost_include="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/include";pwd`"
boost_lib="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/armeabi/lib";pwd`"

make distclean
./configure --prefix=/armeabi --host=arm-linux-androideabi --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --enable-examples=no --enable-thread-safe-observer-pattern
make -j6
make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR}

armeabiEOF

#Create the following shell script for armeabi-v7a
cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/build-armeabi-v7a.sh << 'armeabi-v7aEOF'
#!/bin/bash
# build-armeabi-v7a.sh
BUILD_DIR=android-build
mkdir -p ${BUILD_DIR}
INSTALL_DIR="`pwd`/${BUILD_DIR}"
YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`"
NDK_DIR="${HOME}/Library/Android/sdk/ndk-bundle"
YOUR_PATH_TO_NDK="`cd "${NDK_DIR}";pwd`"
YOUR_TOOLCHAIN=${YOUR_PATH_TO_NDK}/sources/android-toolchain-arm
export CC=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-gcc
export CXX=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-g++
export CPP=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-cpp
export AR=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ar
export RANLIB=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ranlib
export LD=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ld
export CPPFLAGS="-fexceptions -frtti -fpic -ffunction-sections -funwind-tables -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections"
export CXXFLAGS="-D_REENTRANT -D_GLIBCXX__PTHREADS -march=armv7-a -msoft-float -mfpu=neon -mthumb -DANDROID -D__ANDROID__ -DNDEBUG -O2 -g"
export LDFLAGS="-march=armv7-a -Wl,--fix-cortex-a8"
sysroot=${YOUR_TOOLCHAIN}
boost_include="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/include";pwd`"
boost_lib="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/armeabi-v7a/lib";pwd`"

make distclean
./configure --prefix=/armeabi-v7a --host=arm-linux-androideabi --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --enable-examples=no --enable-thread-safe-observer-pattern
make -j6
make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR}

armeabi-v7aEOF

#Create the following shell script for arm64-v8a
cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/build-arm64-v8a.sh << 'arm64-v8aEOF'
#!/bin/bash
# build-arm64-v8a.sh
BUILD_DIR=android-build
mkdir -p ${BUILD_DIR}
INSTALL_DIR="`pwd`/${BUILD_DIR}"
YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`"
NDK_DIR="${HOME}/Library/Android/sdk/ndk-bundle"
YOUR_PATH_TO_NDK="`cd "${NDK_DIR}";pwd`"
YOUR_TOOLCHAIN=${YOUR_PATH_TO_NDK}/sources/android-toolchain-arm64
export CC=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-gcc
export CXX=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-g++
export CPP=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-cpp
export AR=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-ar
export RANLIB=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-ranlib
export LD=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-ld
export CPPFLAGS="-fexceptions -frtti -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections"
export CXXFLAGS="-D_REENTRANT -D_GLIBCXX__PTHREADS -march=armv8-a -mtune=cortex-a53 -DANDROID -D__ANDROID__ -DNDEBUG -O2 -g"
export LDFLAGS="-march=armv8-a"
sysroot=${YOUR_TOOLCHAIN}
boost_include="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/include";pwd`"
boost_lib="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/arm64-v8a/lib";pwd`"

make distclean
./configure --prefix=/arm64-v8a --host=aarch64-linux-android --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --enable-examples=no --enable-thread-safe-observer-pattern
make -j6
make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR}

arm64-v8aEOF

#run shell scripts to clean and build for Android
cd ~/Library/Android/sdk/ndk-bundle/sources
cd QuantLib-1.9
rm -fr android-build
sh build-x86.sh
sh build-x86_64.sh
sh build-armeabi.sh
sh build-armeabi-v7a.sh
sh build-arm64-v8a.sh

(5) Create Android.mk at ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/ for ndkBuild in Android Studio

~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/Android.mk
# create the following Android.mk
cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/Android.mk << 'EOF'
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libQuantLib
LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libQuantLib.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/$(TARGET_ARCH_ABI)/include
LOCAL_CPP_FEATURES := rtti exceptions
include $(PREBUILT_STATIC_LIBRARY)
EOF

(6) Demo of using boost c++ libraries for ndkBuild in Android Studio 2.2.2
Assume prebuilt libraries are installed to ~/Library/Android/sdk/ndk-bundle/sources

app/build.gradle
apply plugin: 'com.android.application'

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def sdkFolder = properties.getProperty('sdk.dir')
def ndkFolder = properties.getProperty('ndk.dir')

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.example.helloboost"
minSdkVersion 9
targetSdkVersion 23
versionCode = 1
versionName = '1.0'
archivesBaseName = 'HELLOBOOST_' + versionName

ndk {
moduleName "hello-boost"
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
externalNativeBuild {
ndkBuild {
arguments "NDK_APPLICATION_MK=src/main/jni/Application.mk"
// default module search path NDK_MODULE_PATH is at ${ndkFolder}/sources
}
}
}

buildTypes {
debug {
minifyEnabled false
zipAlignEnabled true
debuggable true
useProguard false
versionNameSuffix 'debug'
}
release {
minifyEnabled false
zipAlignEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}

}

app/src/main/jni/Android.mk
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := hello-boost
LOCAL_SRC_FILES := hello-boost.cpp first.cpp
LOCAL_STATIC_LIBRARIES := libboost_system libboost_thread libboost_program_options libQuantLib

include $(BUILD_SHARED_LIBRARY)
$(call import-module, boost_1_62_0)
$(call import-module, QuantLib-1.9)

app/src/main/jni/Application.mk
APP_STL = gnustl_static
APP_CPPFLAGS = -Wall

(7) HelloJNI, sample of using cmake CMakeLists.txt after adding Boost and QuantLib libraries
Assume prebuilt libraries are installed to ~/Library/Android/sdk/ndk-bundle/sources

app/src/main/cpp/CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)

# build native_app_glue as a static lib
add_library(app-glue STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

# now build app's shared lib
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -frtti -fexceptions")
add_library(hello-jni SHARED
hello-jni.c)

#BOOST
set(Boost_INCLUDE_DIR ${ANDROID_NDK}/sources/boost_1_62_0/android-build/include)
set(Boost_LIBRARY_DIR ${ANDROID_NDK}/sources/boost_1_62_0/android-build/${ANDROID_ABI}/lib)

set(Boost_USE_STATIC_LIBS ON) # only find static libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_COMPILER -gcc)

find_package(Boost COMPONENTS system thread program_options REQUIRED)
#BOOSTEND

#QuantLib
set(QuantLib_INCLUDE_DIR ${ANDROID_NDK}/sources/QuantLib-1.9/android-build/${ANDROID_ABI}/include)
set(QuantLib_LIBRARY_DIR ${ANDROID_NDK}/sources/QuantLib-1.9/android-build/${ANDROID_ABI}/lib)
add_library(QuantLib STATIC IMPORTED)
set_property(TARGET QuantLib PROPERTY IMPORTED_LOCATION ${QuantLib_LIBRARY_DIR}/libQuantLib.a)
#QuantLibEND

# if have QuantLibJNI, uncomment below and add QuantLibJNI to target_link_libraries of hello-jni for c++ classes generated from QuantLib-SWIG-1.9
#add_library(QuantLibJNI SHARED quantlib_wrap.cpp)
#target_link_libraries(QuantLibJNI ${Boost_LIBRARIES} QuantLib)

if(Boost_FOUND)
# Include libraries needed
include_directories(${Boost_INCLUDE_DIR})
include_directories(${QuantLib_INCLUDE_DIR})
target_link_libraries(hello-jni
android
app-glue
log
${Boost_LIBRARIES}
QuantLib)
endif()

app/build.gradle
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId 'com.example.hellojni'
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
archivesBaseName = 'HELLOJNI_' + versionName
externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang'
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
jniDebuggable true
versionNameSuffix 'debug'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
productFlavors {
arm {
ndk {
abiFilter 'armeabi'
}
}
arm7 {
ndk {
abiFilter 'armeabi-v7a'
}
}
arm64 {
ndk {
abiFilter 'arm64-v8a'
}
}
x86 {
ndk {
abiFilter 'x86'
}
}
x86_64 {
ndk {
abiFilter 'x86_64'
}
}
universal {
ndk {
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
}

(8) Download & Compile swig and generate java & c++ classes from QuantLib-SWIG-1.9 for Android project

#download and compile swig
cd ~/Downloads
curl -O http://nchc.dl.sourceforge.net/project/swig/swig/swig-3.0.10/swig-3.0.10.tar.gz
tar xzvf swig-3.0.10.tar.gz
curl -O http://nchc.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz
tar xzvf pcre-8.39.tar.gz

cd ~/Downloads/pcre-8.39
./configure --enable-utf8 --enable-unicode-properties
make
sudo make install
cd ~/Downloads/swig-3.0.10
./configure
make
sudo make install

# download QuantLib-SWIG-1.9
cd ~/Library/Android/sdk/ndk-bundle/sources
curl -O http://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.9/other%20languages/QuantLib-SWIG-1.9.tar.gz
tar xzvf QuantLib-SWIG-1.9.tar.gz

# generate SWIG java & c++ classes to HelloJNI project
cd ~/Projects
cd HelloJNI/app/src/main
mkdir -p cpp
mkdir -p java/org/quantlib
swig -java -c++ -module QuantLib -package org.quantlib -outdir java/org/quantlib -o cpp/quantlib_wrap.cpp ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-SWIG-1.9/SWIG/quantlib.i

how-to-build-c-static-libraries-boost的更多相关文章

  1. Using Open Source Static Libraries in Xcode 4

    Using Open Source Static Libraries in Xcode 4 Xcode 4.0.1 allows us to more easily create and use th ...

  2. 「操作系统」:Linker Use static Libraries

    While static libraries are useful and essential tools, they are also a source of confusion to progra ...

  3. Creating and Using Static Libraries for iPhone using Xcode 4.3

    Recently, after developing a collection of applications for iPhone that were intended to be used as ...

  4. Build fat static library (device + simulator) using Xcode and SDK 4+

    155down votefavorite 185 It appears that we can - theoretically - build a single static library that ...

  5. Building Objective-C static libraries with categories

    Q: How do I fix "selector not recognized" runtime exceptions when trying to use category m ...

  6. Building Objective-C static libraries with categories(ObjC、all_load、force_load)

    https://developer.apple.com/library/mac/qa/qa1490/_index.html    之所以使用该标志,和Objective-C的一个重要特性:类别(cat ...

  7. Openssl - Static libraries (w32, mingw) 以及对Qt静态编译时的设置

    Openssl static libraries created for Windows 32bit using MinGW compiler   Compiled with:       ./Con ...

  8. MySQL Connector/C++ 8.0 源码编译

    平台 ubuntu 16.04 参考文档: https://dev.mysql.com/doc/dev/connector-cpp/8.0/building.html 下载源码 访问 https:// ...

  9. FFmpeg源代码简单分析:configure

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

随机推荐

  1. motiMaker 软件安装测试

    背景: mitoMaker是一款线粒体/叶绿体组装的pipeline软件,可以从原始的下机数据开始,自动化的组装基因组,注释基因结构,最终生成genebank, fasta 等文件. 整个pipeli ...

  2. MySQL的varchar长度问题

    From: http://blog.csdn.net/longyulu/article/details/7863737 http://dinglin.iteye.com/blog/914276 htt ...

  3. ubuntu下gedit和vim输入中文和中文显示

    安装和配置VIM,参考   http://jingyan.baidu.com/album/046a7b3efd165bf9c27fa915.html?picindex=4 在home/你的用户名 这个 ...

  4. hql date比较

    补充:相等时用to_char,比较大小(<或>)时用 时间格式(如果不是时间格式可以用to_date) java.util.Date date=new java.util.Date(); ...

  5. 安卓开发笔记——Broadcast广播机制(实现自定义小闹钟)

    什么是广播机制? 简单点来说,是一种广泛运用在程序之间的传输信息的一种方式.比如,手机电量不足10%,此时系统会发出一个通知,这就是运用到了广播机制. 广播机制的三要素: Android广播机制包含三 ...

  6. windows mongodb最常用命令简单归纳

    在windows安装好了windows,首先记得要把mongodb bin目录路径放在 系统环境变量的path中,确定之后即配置好了mongo的环境变量,在dos命令框中输入mongo会出现如下 版本 ...

  7. ML基础 : 训练集,验证集,测试集关系及划分 Relation and Devision among training set, validation set and testing set

    首先三个概念存在于 有监督学习的范畴 Training set: A set of examples used for learning, which is to fit the parameters ...

  8. MVC多语言设置 实战简洁版

    此方式可以通过更改进行更改进程语言设定,支持从系统获取默认的区域设定,支持自定义,自定义的方式可以为cookie,可为资料库获取,session等方式. 具体怎么设定就看个人需要了. 第一步: 添加资 ...

  9. What's new in JDK 8

    (1)http://docs.oracle.com/javase/8/docs/technotes/guides/language/enhancements.html#javase8 (2)https ...

  10. 数据库事务MTDC出错解决办法

    Communication with the underlying transaction manager has failed 与基础事务管理器的通信失败 排除步驟: 1.檢查MS DTC 設置.[ ...