0, the way to build is
./build.py path_to_your_ndk_folder
1, you need to download Boost by yourself and put it inside the Boost-for-Android folder, for details of building Boost-for-Android check Boost-for-Android share my experience.
2, if Boost-for-Android is successfully built, then you have files like "libboost_xx-gcc-mt-1_55.a" in "Boost-for-Android/build/lib" folder, now when you build again, you may have
warnings:
Android NDK: WARNING:/Users/ABC/Work/Libs/caffe-android-lib/caffe-mobile/jni/Android.mk:caffe: non-system libraries in linker flags: -lboost_random-gcc-mt-1_55 -lboost_math_tr1-gcc-mt-1_55 -lboost_system-gcc-mt-1_55 -lboost_thread-gcc-mt-1_55 -lboost_date_time-gcc-mt-1_55
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
and errors:
[armeabi-v7a] Compile++ arm : caffe <= math_functions_eigen.cpp
[armeabi-v7a] Compile++ arm : caffe <= upgrade_proto.cpp
[armeabi-v7a] SharedLibrary : libcaffe.so
./boost/exception/detail/type_info.hpp:68: error: undefined reference to 'std::type_info::before(std::type_info const&) const'
./boost/exception/detail/type_info.hpp:68: error: undefined reference to 'std::type_info::before(std::type_info const&) const'
./boost/exception/detail/type_info.hpp:68: error: undefined reference to 'std::type_info::before(std::type_info const&) const'
./boost/exception/detail/type_info.hpp:68: error: undefined reference to 'std::type_info::before(std::type_info const&) const'
./boost/atomic/detail/lockpool.hpp:36: error: undefined reference to 'boost::atomics::detail::lockpool::get_lock_for(void const volatile*)'
./boost/atomic/detail/lockpool.hpp:36: error: undefined reference to 'boost::atomics::detail::lockpool::get_lock_for(void const volatile*)'
./boost/atomic/detail/lockpool.hpp:36: error: undefined reference to 'boost::atomics::detail::lockpool::get_lock_for(void const volatile*)'
./boost/atomic/detail/lockpool.hpp:36: error: undefined reference to 'boost::atomics::detail::lockpool::get_lock_for(void const volatile*)'
collect2: error: ld returned 1 exit status
make: *** [/Users/ABC/Work/Libs/caffe-android-lib/caffe-mobile/obj/local/armeabi-v7a/libcaffe.so] Error 1
The reason for the warning is because the Boost-for-Android libraries built right now are static libraries, but in "caffe-mobile/jni/Android.mk" file, it uses "LOCAL_LDLIBS += ..." to link these static libraries,
#LOCAL_LDLIBS += -lboost_random-gcc-mt-1_55 \
-lboost_math_tr1-gcc-mt-1_55 \
-lboost_system-gcc-mt-1_55 \
-lboost_thread-gcc-mt-1_55 \
-lboost_date_time-gcc-mt-1_55
which i guess could be wrong. So i comment these lines and the correct way to link static libraries in Android.mk file is first:
include $(CLEAR_VARS)
LOCAL_MODULE := ANameYouLike
LOCAL_SRC_FILES := PathToTheStaticLibFolder/lib***.a
include $(PREBUILT_STATIC_LIBRARY)
then link to it:
include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES := ANameYouLike
include $(BUILD_SHARED_LIBRARY)
Above gives an example to link to one static library, now we need to link to multiple static libraries, then have to repeat
include $(CLEAR_VARS)
LOCAL_MODULE := ANameYouLike
LOCAL_SRC_FILES := PathToTheStaticLibFolder/lib***.a
include $(PREBUILT_STATIC_LIBRARY)
multiple times and then link to all of them
include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES += ANameYouLike1 ANameYouLike2
include $(BUILD_SHARED_LIBRARY)
So finally the corresponding part in my Android.mk file are:
# C++ full library
# =======================================================
## Import Protocolbuffer
include $(CLEAR_VARS)
LOCAL_MODULE := protobuf
LOCAL_SRC_FILES = $(LOCAL_PATH)/../../protobuf/obj/local/$(TARGET_ARCH_ABI)/libprotobuf.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../protobuf/jni/src
include $(PREBUILT_STATIC_LIBRARY)
## Import Boost
include $(CLEAR_VARS)
LOCAL_MODULE := boost_random
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../Boost-for-Android/build/lib/libboost_random-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := boost_math_tr1
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../Boost-for-Android/build/lib/libboost_math_tr1-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := boost_system
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../Boost-for-Android/build/lib/libboost_system-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := boost_thread
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../Boost-for-Android/build/lib/libboost_thread-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := boost_date_time
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../Boost-for-Android/build/lib/libboost_date_time-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := boost_atomic
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../Boost-for-Android/build/lib/libboost_atomic-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
and
LOCAL_STATIC_LIBRARIES += protobuf
LOCAL_CPPFLAGS += -pthread -fPIC -fexceptions -frtti -std=c++11 -DUSE_EIGEN -DCPU_ONLY
# boost
LOCAL_LDLIBS += -lm -llog -L$(LOCAL_PATH)/../../Boost-for-Android/build/lib/
#LOCAL_LDLIBS += -lboost_random-gcc-mt-1_55 \
-lboost_math_tr1-gcc-mt-1_55 \
-lboost_system-gcc-mt-1_55 \
-lboost_thread-gcc-mt-1_55 \
-lboost_date_time-gcc-mt-1_55 \
-lboost_atomic-gcc-mt-1_55
LOCAL_STATIC_LIBRARIES += boost_random boost_math_tr1 boost_system boost_thread boost_date_time boost_atomic
the correct way of linking static libraries will get rid of the warning and errors involved "type_info.hpp", adding link to "libboost_atomic-gcc-mt-1_55.a" will get rid of the error involved "lockpool.hpp".
After these steps, i can finally build successfully with "libcaffe.so" and "libcaffe_jni.so" generated in folder "caffe-mobile/libs/armeabi-v7a".