opencv: Error from STL library while compiling for Android with ANDROID_STL=c++_static(shared)

  • OpenCV => 3.2
  • Operating System / Platform => OSX

I have failed to compile opencv with NDK after setting ANDROID_STL to c++_static or c++_shared. I have tried NDK r11 through r14, after fixing the NDK folder structuring problem, I still get errors while compiling any files that include STL headers such as <iostream>. Error messages are like the following:

In file included from /path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/cwchar:107:0,
                 from /path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/string:438,
                 from /path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/__locale:15,
                 from /path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/ios:216,
                 from /path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/iostream:38,
                 from /opencv/3rdparty/libtiff/tiffio.hxx:34,
                 from /opencv/3rdparty/libtiff/tif_stream.cxx:31:
/path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/cwctype:88:9: error: '::iswblank' has not been declared
 using ::iswblank;
         ^
In file included from /path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/string:438:0,
                 from /path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/__locale:15,
                 from /path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/ios:216,
                 from /path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/iostream:38,
                 from /opencv/3rdparty/libtiff/tiffio.hxx:34,
                 from /opencv/3rdparty/libtiff/tif_stream.cxx:31:
/path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/cwchar:132:9: error: '::vfwscanf' has not been declared
 using ::vfwscanf;
         ^
/path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/cwchar:133:9: error: '::vswscanf' has not been declared
 using ::vswscanf;
         ^
/path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/cwchar:134:9: error: '::vwscanf' has not been declared
 using ::vwscanf;
         ^
/path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/cwchar:150:9: error: '::wcstof' has not been declared
 using ::wcstof;
         ^
/path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/cwchar:151:9: error: '::wcstold' has not been declared
 using ::wcstold;
         ^
/path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/cwchar:155:9: error: '::wcstoll' has not been declared
 using ::wcstoll;
         ^
/path/to/ndk/sources/cxx-stl/llvm-libc++/libcxx/include/cwchar:159:9: error: '::wcstoull' has not been declared
 using ::wcstoull;

and there’re hundreds more of them. Have tried replacing the toolchain from NDK/build/cmake as well as standalone toolchain exported from NDK/build/tools/make-standalone-toolchain.sh, all efforts failed and resulted in the same error as above.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Android NDK provides own CMake toolchain file since r15. So solution is very simple - use it instead of custom OpenCV version (which leave for legacy NDKs).

Try something like this:

cmake -GNinja -DINSTALL_ANDROID_EXAMPLES=ON -DANDROID_EXAMPLES_WITH_LIBS=ON -DBUILD_EXAMPLES=ON -DBUILD_DOCS=OFF -DWITH_OPENCL=OFF -DWITH_IPP=ON -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN=clang “-DANDROID_STL=c++_static” -DANDROID_ABI=x86 -DANDROID_SDK_TARGET=18 …/opencv

--     Android ABI:                 x86
--     NDK toolchain:               i686-linux-android-clang
--     STL type:                    c++_static
--     Native API level:            14
--   Android SDK:                   /opt/android/android-sdk (tools: 25.2.5 build tools: 27.0.2)
--     android tool:                /opt/android/android-sdk/tools/android
--     SDK target:                  android-18
--     Projects build scripts:      Ant/Eclipse compatible

This works! Thank you very much!

Hi all,

I’m hitting the same issue, trying to compile OpenCV 3.4.1 or HEAD with c++_static and NDKr16.

I need C++11, so gnustl is not an option, and it appears to be impossible to set clang as the compiler.

This makes OpenCV not usable together with C++11 on Android, not to mention that gcc support is going to be discontinued in NDKr17 (coming very soon) and will be removed in NDKr18: https://github.com/android-ndk/ndk/wiki/Changelog-r17-beta2.

I could contribute some code, but I need some advice on where to start: the cmake files in OpenCV take thousands of lines of mostly undocumented code.

@feliwir ,

  1. Try NDK15+ with builtin native CMake toolchain.
  2. Disable OpenCV tracing support here.

BTW, Android NDK r15 has own CMake toolchain for Android - you could try to use it.