Ask Your Question

Need "How To" to Rebuild OpenCV v2.4.12 and v.3.1 for Android and NDK 11

asked 2016-03-31 13:45:33 -0500

I trying to rebuild OpenCV static libraries for the Android ABIs of: armeabi, armeabi-7a, mips, x86.

I'm using Android Studio (because Eclipse is deprecated) latest and greatest version on Mac OS X.

I using NDK 11 that recommends Clang3.8, GCC is deprecated. Use the APP_STL ( of libc++ instead of libstdc++.

Threading Building Blocks (libtbb.a) support: clearly indicate or configure in CMake generator for Android on Mac OS X whether tbb is supported for one more of the Android ABIs.

My current problem is the following link error building a shared library for an Android APK where a static library created by the OpenCV Android armeabi-7a CMake build does not link with libtbb.a, that was created by the same build process:
function tbb::interface7::internal::auto_partition_type::auto_partition_type(tbb::auto_partitioner const&):
error: undefined reference to 'tbb::internal::get_initial_auto_partitioner_divisor()'
[Many more errors like this one...]

Here is my cmake command: cmake \
-DCMAKE_C_FLAGS_RELEASE="-Os -DNDEBUG -fvisibility=hidden -ffunction-sections -fstack-protector-all" \
-DCMAKE_CXX_FLAGS_RELEASE="-Os -DNDEBUG -fvisibility=hidden -ffunction-sections -fstack-protector-all -fvisibility-inlines-hidden" \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 \
-DANDROID_STL=c++_static \
-DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake \

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2016-04-01 03:42:38 -0500

mshabunin gravatar image

You can try to use script for 3.x version. Here is an example build log: build log

python ../opencv/platforms/android/ . ../opencv

Run with --help to see available parameters. And don't forget to set ANDROID_SDK and ANDROID_NDK environment variables.

edit flag offensive delete link more

answered 2016-04-08 12:54:06 -0500

The link error resulted from me fat fingering a change of an assign operator, ":=", to a plus-equal operator, "+=", in the OpenCV produced file for Android cross-compilation. But the overall problem with CMake generated build environments remain. That is the initial CMake configuration definition settings are only known to the CMake project author. This requires the CMake project author to correctly and clearly document the CMake definitions that will build the specific target, whether it is a cross-compiling build environment or a platform specific build environment. Without proper documentation, it's is very hard to reverse engineer the CMake project/script/package, whatever you call it, to figure how platform specific build configuration settings map to CMake configuration definitions.

edit flag offensive delete link more


The documentation can be found in the file header: toolchain file

mshabunin gravatar imagemshabunin ( 2016-04-12 10:54:16 -0500 )edit

Question Tools



Asked: 2016-03-31 13:45:33 -0500

Seen: 679 times

Last updated: Apr 08 '16