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 th