Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vcpudding opened this issue May 17, 2017 · 15 comments

Comments

@vcpudding
Copy link

commented May 17, 2017

  • 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 . 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.

@alalek

This comment has been minimized.

Copy link
Contributor

commented May 17, 2017

What your toolchain compiler? clang/gcc?

http://stackoverflow.com/questions/30541066/android-ndk-cwctype-and-string-build-errors
suggests gnustl_static.

Usage questions should go to Users OpenCV Q/A forum: http://answers.opencv.org

@vcpudding

This comment has been minimized.

Copy link
Author

commented May 18, 2017

Compiler was gcc.

I found an identical question on OpenCV Q&A forum at http://answers.opencv.org/question/118379/build-failure-with-android-ndk-r13b-and-c_shared/

Because there's no reply to the question, I posted an issue here. Sorry for the confusion.

The reason I can't switch to gnustl_static is that I have the ceres-solver static library included in my project, which uses lots of C++11 stuff and would not compile with any STLs on Android except for c++_static or c++_shared.

@alalek

This comment has been minimized.

Copy link
Contributor

commented May 18, 2017

But headers are from this path:

llvm-libc++

so compiler should be clang.

@projectcs2103t

This comment has been minimized.

Copy link

commented Jul 27, 2017

So is it true that currently for opencv you can only build with gcc although gcc has been deprecated in new ndk versions?

@alalek

This comment has been minimized.

Copy link
Contributor

commented Jul 27, 2017

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

@pseandersson

This comment has been minimized.

Copy link

commented Oct 26, 2017

the c++ headers are added in wrong order. See android/ndk#452

@feliwir

This comment has been minimized.

Copy link

commented Jan 22, 2018

Any updates on this? I am getting this on API 14 with libc++ and NDK r16:

In file included from D:/opencv/modules/core/src/trace.cpp:15:
D:/android-ndk-r16/sources/cxx-stl/llvm-libc++/include\fstream:824:9: error: use of undeclared identifier 'fseeko' 
@alalek

This comment has been minimized.

Copy link
Contributor

commented Jan 22, 2018

@feliwir ,

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

This comment has been minimized.

Copy link

commented Jan 22, 2018

@alalek
1.
I can’t use the builtin toolchain, since our codebase defines a lot platform specific variables in that. I am using NDK16 already, but the builtin CMake toolchain always made a great job.
2.
Thanks i will definetly try that.

@progre55

This comment has been minimized.

Copy link

commented Mar 31, 2018

@feliwir any luck so far? I'm hitting the same issues trying to compile OpenCV version 3.2.0 with c++_static and NDKr16, using the NDK native CMake toolchain.

@davnat

This comment has been minimized.

Copy link

commented Apr 30, 2018

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.

@alalek

This comment has been minimized.

Copy link
Contributor

commented Apr 30, 2018

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
@davnat

This comment has been minimized.

Copy link

commented May 2, 2018

This works! Thank you very much!

@arghasilitonga

This comment was marked as off-topic.

Copy link

commented Oct 20, 2018

@alalek I can't fix this issue with your suggestion. I build this project on android studio

@alalek alalek closed this Nov 3, 2018

@aitazhixin

This comment was marked as off-topic.

Copy link

commented May 9, 2019

#8742 (comment)
How can i produce only one file libopencv_java3.so?

i hava solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
10 participants
You can’t perform that action at this time.