对于手臂交叉编译使用crystax NDK [英] Cross compiling for arm using crystax NDK

查看:694
本文介绍了对于手臂交叉编译使用crystax NDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由谷歌提供了Android NDK是不能编译调用C ++ 11的功能,如的std :: to_string() STD: :stoul 等{我在 r10b试过一个来自官方网站}。因此,在这样的建议是尝试 crystax NDK 。我已经下载并放在旁边的谷歌的NDK的根文件夹。所有我在根文件的CMakeLists.txt变化是:

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:

从:

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 "")

要:

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 "")

和从cmake的命令行:

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

要:

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

即,由正常NDK改为crystax-NDK。该计划编制罚款previously直到它试图编译文件,调用标准:: to_string()等,但改变后的CMake给出了一个错误,它无法编译一个简单的测试程序,因为:

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

我可以看到libcrystax.a和.so在directorie:

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

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

我想就在文件的CMakeLists.txt过多的开头添加link_directories(路径到上面的),但它还是不解决这个问题。

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.

应该找到它(我提供上述--sysroot等后),就像正常的NDK。那么如何来解决呢?任何其他cmake的变量设置还是怎么了?

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 ?

推荐答案

我不知道您的基于CMake的构建系统是如何工作的,但实际上,如果你正确地添加路径 /一些路径/安卓-ndk-R8-crystax-1 /来源/ crystax /库/ armeabi-V7A 来链接搜索路径,它应该找到libcrystax和链路与它成功。

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.

请注意,NDK有几个部分隔开的每个其他 - 即SYSROOT,libcrystax,C ++库 - 所有被分开。它是做与NDK工作建立系统,该系统提供了一定的灵活性选择C ++标准库的实施,以及NDK构建系统知道在哪里可以找到他们。你的情况,这种方法也不是那么好,所以我建议你先独立的工具链,它包含组装在一起的一切。换句话说,这将是经典的交叉编译工具链,其中包含SYSROOT,libcrystax和GNU C ++已知的编译器/连接的地方标准库没有任何额外的选择传球。

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.

要创建这样的工具链,cd到NDK根目录,然后运行以下命令:

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

然后使用 $ HOME / ARM-Linux的androideabi 作为完全独立的工具链为基于CMake的构建系统。

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

请注意,但是,与CrystaX NDK R8内置该应用程序将无法在最新的Andr​​oid 5.0由于仿生(libc中)的变化运行。 previous的Andr​​oid版本(小于4.4 =),无一不精。我们即将推出的R10版本,它是在最后的测试阶段修复这个问题(和许多其他)。在此期间,你可以通过你的项目给我们的R8释放和快速切换到时候做R10 - 同样的方法将与R10以及与R8工作

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.

这篇关于对于手臂交叉编译使用crystax NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆