android-ndk-r8d 使用 独立 编译 工具链 官方文档 中英文 对照
USING THE ANDROID TOOLCHAIN AS A STANDALONE COMPILER使用ANDROID作为一个独立的编译器工具链
======================================================
It is now possible to use the toolchains provided with the Android NDK as
standalone compilers. This can be useful if you already have your own build
system, and only need to ability to invoke the cross-compiler to add support
to Android for it.
现在可以使用Android NDK 作为独立编译器。如果你拥有自己的编译系统这会很有用
,仅仅需要有调用支持Android交叉编译器的能力。
A typical use case if invoking the 'configure' script of an open-source
library that expects a cross-compiler in the CC environment variable.
一个典型用例,如果调用需要交叉编译器调用开源库'configure'脚本(预设CC环境变量)。
This document explains how to do that:
该文档解释了如何做:
1/ Selecting your toolchain:
选择你的工具链:
----------------------------
Before anything else, you need to decide whether your standalone toolchain
is going to target ARM-based devices, x86-based, or MIPS-based one.
Each architecture corresponds to a different toolchain name. For example:
做任何东西之前,你需要决定你的独立的工具链是基于arm的设备,基于x86的,或基于mips的哪一个。
每个架构对应一个不同的工具链的名字。例如:
* arm-linux-androideabi-4.6 => targeting ARM-based Android devices
* x86-4.6 => targeting x86-based Android devices
* mipsel-linux-android-4.6 => targeting MIPS-based Android devices
2/ Selecting your sysroot:
选择目录切换为sysroot:
--------------------------
The second thing you need to know is which Android native API level you want
to target. Each one of them provides a different various APIs, which are
documented under doc/STABLE-APIS.html, and correspond to the sub-directories
of $NDK/platforms.
第二件事你需要知道的是,你需要知道安卓原生API的级别。每一个都提供了一个不同的各种api,
这是记录在doc/STABLE-APIS.html和对应 $NDK/platforms的子目录中
This allows you to define the path to your 'sysroot', a GCC term for a
directory containing the system headers and libraries of your target.
Usually, this will be something like:
定义'sysroot'包含目标系统头文件和库。通常,如下:
SYSROOT=$NDK/platforms/android-<level>/arch-<arch>/
Where <level> is the API level number, and <arch> is the architecture
("arm", "x86", and "mips" are the supported values). For example, if you're
targeting Android 2.2 (a.k.a. Froyo), you would use:
<level>是API 级别 号,<arch>是架构(支持arm,x86,mips)。
例如:如果目标android是2.2,如下:
SYSROOT=$NDK/platforms/android-8/arch-arm
IMPORTANT: Note that X86 and MIPS architectures are only supported at android-9 and later.
重要:注意X86和MIPS架构只在android-9或更新支持。
3/ Invoking the compiler (the hard way):
调用编译器(最困难一步)
----------------------------------------
Invoke the compiler using the --sysroot option to indicate where the system
files for the platform you're targeting are located. For example, do:
使用--sysroot选项来指出系统文件位置在哪。例如:
export CC="$NDK/toolchains/<name>/prebuilt/<system>/bin/<prefix>gcc --sysroot=$SYSROOT"
$CC -o foo.o -c foo.c
Where <name> is the toolchain's name, <system> is the host tag for your system,
and <prefix> is a toolchain-specific prefix. For example, if you are on Linux
using the NDK r5 toolchain, you would use:
<name>是工具链的名字,<system>是系统主机标志,<prefix>是工具链特定前缀,例如在linux下使用NDK r5工具链,如下:
export CC="$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot=$SYSROOT"
As you can see, this is rather verbose, but it works!
可见,这是很繁琐,但是有效!
IMPORTANT NOTE:
重要事项:
Using the NDK toolchain directly has a serious limitation:
You won't be able to use any C++ STL (either STLport or
the GNU libstdc++) with it. Also no exceptions and no RTTI.
直接使用NDK的工具链(非独立版工具链)有严重的限制:
你不能使用任何C++ STL(STLport或GNU libstdc++)。也没有异常和运行时类型检查。
4/ Invoking the compiler (the easy way):
调用编译器(最简单一步):
----------------------------------------
The NDK allows you to create a "customized" toolchain installation to make
life easier. For example, consider the following command:
NDK允许您创建一个“定制”工具链安装。例如,参考下面的命令:
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-5 --install-dir=/tmp/my-android-toolchain
This will create a directory named /tmp/my-android-toolchain containing a
copy of the android-5/arch-arm sysroot, and of the toolchain binaries.
这将建立一个路径/tmp/my-android-toolchain,包含复制的 android-5/arch-arm sysroot 工具链 文件。
Note that by default, the ARM-based GCC 4.6 toolchain will be selected by the script.
Use the '--arch=x86' option to specify the x86 GCC 4.6, or add '--arch=mips' option
to specify the MIPS GCC 4.6, or alternatively
'--toolchain=<name>'. For example:
注意默认使用ARM GCC 4.6 工具链。使用'--arch=x86'设定x86 GCC 4.6,
或'--arch=mips'设定MIPS GCC 4.6,或者'--toolchain=<name>'来设。例如
--toolchain=x86-4.4.3 # select x86 GCC 4.4.3 compiler
--toolchain=arm-linux-androideabi-4.7 # select ARM GCC 4.7 compiler
--toolchain=mipsel-linux-android-4.6 # select MIPS GCC 4.6 compiler, same as --arch=mips
If you wish, add '--llvm-version=3.1' to also copy clang/llvm 3.1, or
use --toolchain with '-clang3.1' suffix. For example:
'--llvm-version=3.1'可以复制clang/llvm 3.1或使用--toolchain with '-clang3.1'后缀,例如:
--toolchain=arm-linux-androideabi-clang3.1 # same as --arch=arm --llvm-version=3.1
You can later use it directly with something like:
稍后可用类似如下(导入环境变量):
export PATH=/tmp/my-android-toolchain/bin:$PATH
export CC=arm-linux-androideabi-gcc # or export CC=clang
export CXX=arm-linux-androideabi-g++ #
补充:移动开发 , Android ,