Cross-compiling the hand using the NDK kristax

Android ndk, provided google, can not compile a call to C ++ functions 11, such as std::to_string()

and std::stoul

etc. {I tried it in r10b

one from the official site}. So the suggestion in SO was to try it crystax NDK

. I downloaded and placed the root folder next to the Google 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 from the command line:

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

      

those. changed from normal ndk to crystallax-ndk. The program was compiled before it tried to compile the file with a call to std :: to_string (), etc. But after the change, Cmake gives an error that it cannot 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 see libcrystax.a and .so in the directory:

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

      

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

It should find it there (after I put --sysroot and so on above) just like normal ndk. So how should this be resolved? Any other cmake variable that needs to be set or something?

+3


source to share


1 answer


I don't know how your cmake based build system works, but in fact, if you added the path /some-path/android-ndk-r8-crystax-1/sources/crystax/libs/armeabi-v7a

to the linker search path correctly , it should find libcrystax and link to it successfully.

Note that the NDK has several seperated sections - for example, sysroot, libcrystax, C ++ - all seperated. This is done to work with the NDK build system, which offers some flexibility in choosing a standard C ++ library implementation, and the NDK build system knows where to find them. In your case, this approach is not so good, so I suggest that you first create a standalone toolchain that contains everything put together. In other words, it would be a classic toolchain cross-compilation that contains the sysroot standard library, libcrystax and GNU C ++ in places known to the compiler / linker, without passing any additional parameters.

To create such a toolchain, cd to the 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 it $HOME/arm-linux-androideabi

as a complete stand-alone toolchain for your cmake-based build system.

Please note that an application built with CrystalaX NDK r8 will not work on the latest Android 5.0 due to changes in Bionic (libc). Previous versions for Android (<= 4.4) are fine. We have fixed this issue (and many more) in the upcoming r10 release, which is in final testing. In the meantime, you can migrate your project to our r8 version and quickly switch to r10 when it's done - the same approach will work with r10 as well as r8.

+5


source







All Articles