opencv在交叉编译的时候的一些常见报错和处理---How to use std::stoul and std::stoull in Android?


How to use std::stoul and std::stoull in Android?

Ask Question Asked 8 years, 7 months ago Modified 6 years, 2 months ago Viewed 13k times    

C++11 has two new string conversion functions into unsigned long and long longstd::stoul() and std::stoll().

The recent Android NDK r9 introduces Clang 3.3 compiler which is said to be C++11 feature complete. There are prototypes for these functions deep inside NDK, however I cannot use them.

What do I need to do to use them?

P.S. I already do LOCAL_CPPFLAGS += -std=c++11

androidc++c++11android-ndk Share   edited Nov 26, 2015 at 15:09     asked Jul 30, 2013 at 15:11 Sergey K. 24k1313 gold badges100100 silver badges173173 bronze badges
  • 3 Probably similar to this stackoverflow.com/questions/15616254/…. but instead use clangs c++11 library. (I think its -stdlib=libc++ -std=c++11 for the LOCAL_CFLAGS)  – FDinoff  Jul 30, 2013 at 15:24
  •   I already do -std=c++11  – Sergey K.  Jul 30, 2013 at 16:01
  •   -stdlib=libc++ is also needed make sure you try it  – aaronman  Jul 30, 2013 at 17:14
  •   Added -stdlib=libc++ and defined GXX_EXPERIMENTAL_CXX0X Still no success.  – Sergey K.  Jul 30, 2013 at 18:36
  • 2 I have no idea. I can't get this to work. I think some define is missing but I can't tell which. If you do a -E to show the preprocessor output you can see that bits/basic_string.h is included and that appears to be where stoll is defined however stoll does not appear in the preprocessor output.  – FDinoff  Jul 30, 2013 at 18:50
Add a comment CrystaX's Android NDK which seems to have extensions over the Vanilla Android NDK.

Note: __GXX_EXPERIMENTAL_CXX0X__ is defined by adding -std=gnu++11 to APP_CXXFLAGS or LOCAL_CXXFLAGS

Detailed Test log: Built using NDK version r8e
jni/Application.mk:

APP_STL := gnustl_static
APP_CXXFLAGS += -std=gnu++11
NDK_TOOLCHAIN_VERSION := 4.7

jni/Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := cxx11
LOCAL_SRC_FILES := cxx11.cpp
include $(BUILD_EXECUTABLE)

jni/cxx11.cpp:

#include 
#include 

int main(int argc, char* argv[]) {
#if defined(__GXX_EXPERIMENTAL_CXX0X__)
    std::cout<<"__GXX_EXPERIMENTAL_CXX0X__ defined."<

Output on Nexus 4 (Android 4.3):

u0_a51@mako:/ $ /data/local/tmp/cxx11
__GXX_EXPERIMENTAL_CXX0X__ defined.
_GLIBCXX_USE_C99 not defined.
_GLIBCXX_HAVE_BROKEN_VSWPRINTF not defined.
No support for stoll/stoul.
Share   edited Aug 8, 2013 at 12:59     answered Aug 8, 2013 at 11:16 Samveen 3,4523434 silver badges5151 bronze badges
  •   Any chance to replace stdlib?  – Sergey K.  Aug 8, 2013 at 11:19
  •   @SergeyK. Try CrystaX's Android NDK, which seems to have some fixes over the Vanilla Android NDK. I am looking to explore it as well.  – Samveen  Aug 8, 2013 at 11:43 
  •   Have you tried NDK r9? Maybe we can define _GLIBCXX_USE_C99 manually?  – Sergey K.  Aug 8, 2013 at 11:44
  •   @SergeyK. Naah. Already tried LOCAL_CFLAGS := -D _GLIBCXX_USE_C99=1.     It's a very deep-rooted problem.  – Samveen  Aug 8, 2013 at 11:46 
  •   Ok, this seems to be a great answer.  – Sergey K.  Aug 8, 2013 at 12:17
Show 6 more comments   Google Groups post.

Share   answered Dec 29, 2015 at 0:40 Mark S. 7111 silver badge33 bronze badges
  •   Did this also fix the issue of access to the unsigned long and long long variants of the functions(stoul and stoll)?  – Samveen  Feb 22, 2016 at 5:14
  •   That solution helped me with stoul(). Thanks.  – Stranger  May 5, 2017 at 16:18
Add a comment

Your Answer

相关