3

The android ndk supplied by google is unable to compile call to c++11 functions such as std::to_string() and std::stoul etc. {I had tried it in r10b one from the official site}. So the suggestion in SO was to try crystax NDK. I have downloaded and placed the root folder next to the google's NDK. All I changed in my root CMakeLists.txt file was:

from:

set(PLATFORM_PREFIX            "/some-path/android-ndk-r10b/platforms/android-19/arch-arm")
set(PLATFORM_FLAGS             "-fPIC -Wno-psabi --sysroot=${PLATFORM_PREFIX}")
set(CMAKE_CXX_FLAGS            "${PLATFORM_FLAGS} -march=armv7-a -mfloat-abi=softfp -mfpu=neon" CACHE STRING "")

To:

set(PLATFORM_PREFIX            "/some-path/android-ndk-r8-crystax-1/platforms/android-14/arch-arm")
set(PLATFORM_FLAGS             "-fPIC -Wno-psabi --sysroot=${PLATFORM_PREFIX}")
set(CMAKE_CXX_FLAGS            "${PLATFORM_FLAGS} -march=armv7-a -mfloat-abi=softfp -mfpu=neon" CACHE STRING "")

and cmake command-line from:

cmake .. -DCMAKE_CXX_COMPILER=/some-path/android-ndk-r10b/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -DCMAKE_C_COMPILER=/some-path/android-ndk-r10b/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -DANDROID_BUILD=ON -DANDROID_NDK_ROOT=/some-path/android-ndk-r10b

To:

cmake .. -DCMAKE_CXX_COMPILER=/some-path/android-ndk-r8-crystax-1/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -DCMAKE_C_COMPILER=/some-path/android-ndk-r8-crystax-1/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -DANDROID_BUILD=ON -DANDROID_NDK_ROOT=/some-path/android-ndk-r8-crystax-1

ie., changed from normal ndk to crystax-ndk. The program was compiling fine previously till it tried to compile a file with call to std::to_string() etc. But after the change Cmake gives an error that it is unable to compile a simple test program because:

  /some-path/android-ndk-r8-crystax-1/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.7/../../../../arm-linux-androideabi/bin/ld:
  error: cannot find -lcrystax

I can see libcrystax.a and .so in directorie:

/some-path/android-ndk-r8-crystax-1/sources/crystax/libs/armeabi-v7a

I tried adding link_directories("path-to-above") right at the beginning of the CMakeLists.txt file too, but that didn't solve it either.

It should find it there (after i supply the --sysroot etc above) just like the normal ndk. So how should this be solved ? Any other cmake variable to be set or something ?

3
  • Not as an answer to your question, and not to diminish the great effort crystax put into their NDK, but FWIW the official NDK with gnu-libstdc++ does support both to_string() and stoul.
    – Alex Cohn
    Nov 13, 2014 at 20:46
  • i just downloaded r10c (that's the latest, no?) and it gives me the exact same errors in same places. I can see some broken Vprintf or something #defining it away in basic-string.h. It works only if i add it into the gnu headers myself into namespace std and provide my own implementation .. but that's undefined behavior to touch namespace std. Would be interested to know how or what you did or i did wrong.
    – ustulation
    Nov 14, 2014 at 6:54
  • 1
    As far as I see, Google's NDK doesn't support std::to_string and stoul. If you look into gnu-libstdc++ headers provided by NDK r10c, you'll see those functions under "#if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99))" condition. Unfortunately, _GLIBCXX_USE_C99 is not defined. It's easy to check - see $NDK/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include/bits/c++config.h. Also, note how many features disabled there. All that addressed in CrystaX NDK so we have full C++ support as opposed to nominal Google's approach. Nov 14, 2014 at 7:54

1 Answer 1

5

I don't know how your cmake-based build system works, but actually if you properly add path /some-path/android-ndk-r8-crystax-1/sources/crystax/libs/armeabi-v7a to linker search paths, it should find libcrystax and link with it successfully.

Please note that NDK have several parts separated each from other - i.e. sysroot, libcrystax, C++ library - all are separated. It is done to work with NDK build system which offer some flexibility choosing C++ standard library implementation, and NDK build system know where to find all of them. In your case this approach is not so good so I suggest you first make standalone toolchain, which contains all things assembled together. In other words, it would be classic cross-compile toolchain which contains sysroot, libcrystax and GNU C++ standard library in places known to compiler/linker without passing of any additional options.

To create such toolchain, cd to NDK root directory and run the following command:

./build/tools/make-standalone-toolchain.sh --system=linux-x86_64 --toolchain=arm-linux-androideabi-4.7 --platform=android-14 --install-dir=$HOME/arm-linux-androideabi

Then use $HOME/arm-linux-androideabi as full standalone toolchain for your cmake-based build system.

Please note, however, that application built with CrystaX NDK r8 will not run on newest Android 5.0 due to changes in Bionic (libc). Previous Android versions (<=4.4) are all fine. We fixed that issue (and many others) in upcoming r10 release which is on final testing stage. In the meantime you could adopt your project to our r8 release and quickly switch to r10 when it done - the same approach will work with r10 as well as with r8.

6
  • Wonderful ! It works that way. The only thing now is that your g++ is 4.7 and our project requires 4.8 and above, so will be anxiously waiting for your r10 you mentioned. I hope it has g++ >= 4.8 (4.9 maybe? :-)
    – ustulation
    Nov 14, 2014 at 6:02
  • 2
    Sure, new r10 have five toolchain versions - based on gcc 4.6, 4.8, 4.9 and clang 3.4 and 3.5 Nov 14, 2014 at 6:38
  • 2
    Just for the record: CrystaX NDK 10 released, containing many features and improvements. Specifically for you may be interesting that CrystaX NDK 10.1 include prebuilt Boost 1.57.0 so Boost usage on Android become as simple as it can be. Jan 20, 2015 at 18:58
  • 1
    Hey Dimitry, i just wanted to thank you for your great drop in place replacement. As of today i didn't learn much about the low level parts of C++ however your NDK enabled me to compile, test and play around with many C libs and Android JNI
    – blender
    May 27, 2015 at 21:52
  • @DmitryMoskalchuk - used make-standalone-toolchain.sh as suggested but didnt seem to copy Boost libs/includes into new toolchain. I'm guessing that I can copy them manualy from the sources/boost folder, but I noticed that there are 4 copys of the libs (gcc4.9, gcc5, etc). How do you suggest I do this? Using crystax-ndk-10.3.1, Linux 64 host, arm and x86 targets, presuming standard gcc for building [if any of that helps])
    – JSON
    Apr 10, 2016 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.