NDK 提供 make-standalone-toolchain.sh
shell 脚本以允许您从命令行执行定制的工具链安装。
脚本位于 $NDK/build/tools/
目录中,其中 $NDK
是 NDK 的安装根目录。 下面展示了使用此脚本的示例:
$NDK/build/tools/make-standalone-toolchain.sh
--arch=arm --platform=android-21 --install-dir=/tmp/my-android-toolchain
cmakelist.txt
project(test)
cmake_minimum_required(VERSION 3.4.1)
set(NDK_STANDALONE_TOOLCHAIN /home/gh/Android/android_arm_gnustl)
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 19)
set(CMAKE_C_COMPILER ${NDK_STANDALONE_TOOLCHAIN}/bin/clang)
set(CMAKE_CXX_COMPILER ${NDK_STANDALONE_TOOLCHAIN}/bin/clang++)
set(CMAKE_FIND_ROOT_PATH ${NDK_STANDALONE_TOOLCHAIN})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie -fPIE -fPIC -O2 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pie -fPIE -fPIC -Ofast -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-function -Wno-narrowing")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")