Building a toolchain with cmake to cross-compile for android

我只是一个虾纸丫 提交于 2019-11-29 21:49:57
ant2009

I managed to solve the problem by first going to this website:

http://developer.android.com/tools/sdk/ndk/index.html

There is an example of using the standalone toolchain that comes with NDK.

make-standalone-toolchain.sh --toolchain=arm-linux-androideabi-4.8

Extracted the into my /opt directory.

And using this sample toolchain cmake file

# Target system
set(CMAKE_SYSTEM_NAME  Android)

set(CMAKE_SYSTEM_VERSION 1)

# Compiler to build for the target
set(CMAKE_C_COMPILER /opt/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-gcc)
set(CMAKE_CXX_COMPILER /opt/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-g++)

Everything just worked after that. However, I couldn't get my previous problem working. Maybe I have set some environmental variables incorrectly to the wrong paths.

Hope this helps someone else.

Why you don't try this android-cmake. I still use this script and it works fairly well. If that approach does not fit your needs, you could use it as an inspiration anyway :-) .

zyzytoby

For original problem from ant2009, please have a try to add following lines in .cmake:

SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=/opt/ndk/platforms/android-23/arch-arm" CACHE STRING "" FORCE)

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=/opt/ndk/platforms/android-23/arch-arm" CACHE STRING "" FORCE)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!