#android-ndk-r8d 使用 独立 编译 工具链 官方文档 中英文 对照

本文档详细介绍了如何将Android NDK提供的工具链作为独立编译器使用,适用于已有自定义构建系统的场景。内容包括选择目标架构、指定sysroot路径、调用编译器的方法,以及通过NDK构建自定义工具链的简便方式。同时,文档也提到了使用过程中的限制,如不支持C++ STL和异常处理,以及Windows、wchar_t支持和C++ STL的注意事项。
摘要由CSDN通过智能技术生成

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值