From a766e6860a51cf2ab83e1462a4314084ab95597e Mon Sep 17 00:00:00 2001
From: David Friedman By default, the NDK build system provides C++ headers for the minimal C++ runtime library
({@code system/lib/libstdc++.so}) provided by the Android system. In addition, it comes with
alternative C++ implementations that you can use or link to in your own applications.
-Use {@code APP_STL} to select one of them. Table 2 shows the {@code APP_STL} values to specify
-support for different libraries.
- Table 2. {@code APP_STL} settings to support different libraries. For more information on this subject, see
-C++ Library Support. The equivalent of {@code LOCAL_SHORT_COMMANDS} in {@code Application.mk} for your whole project.
@@ -222,10 +198,12 @@ To select a version of Clang, define this variable as {@code clang3.4}, {@code c
Starting from Android 4.1 (API level 16), Android's dynamic linker supports position-independent
-executables (PIE). Use the {@code -fPIE} flag to build them. This flag makes it harder to exploit
-memory corruption bugs by randomizing code location. By default, {@code ndk-build} automatically
-sets this value to {@code true} if your project targets {@code android-16} or higher. You may set
-it manually to either {@code true} or {@code false}.
-
-
-
-
- Library
- Value
-
-
- Static STLport
- {@code APP_STL := stlport_static}
-
-
- Shared STLport
- {@code APP_STL := stlport_shared}
-
-
-Default C++ runtime
- {@code APP_STL := system}
- APP_SHORT_COMMANDS
APP_PIE
This flag applies only to executables. It has no effect when building shared or static libraries.
diff --git a/docs/html-ndk/ndk/guides/cpp-support.jd b/docs/html-ndk/ndk/guides/cpp-support.jd index ff170f42d9df4..0074b808aa8fc 100644 --- a/docs/html-ndk/ndk/guides/cpp-support.jd +++ b/docs/html-ndk/ndk/guides/cpp-support.jd @@ -32,7 +32,7 @@ these helper runtimes, their characteristics, and how to use them.Table 1 provides names, brief explanations, and features of runtimes available inthe NDK.
-+
Table 1. NDK Runtimes and Features.
| Architecture | Value | +||
|---|---|---|---|
| armeabi | +{@code -target armv5te-none-linux-androideabi} | +||
| armeabi-v7a | {@code -target armv7-none-linux-androideabi} | ||
| armeabi | -{@code -target armv5te-none-linux-androideabi} | +arm64-v8a | +{@code -target aarch64-none-linux-android} |
| x86 | {@code -target i686-none-linux-android} | ||
| MIPS | +|||
| x86_64 | +{@code -target x86_64-none-linux-android} | +||
| mips | {@code -target mipsel-none-linux-android} |
-export CC="export CC="$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/ \ +export CC="$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/ \ linux-x86/bin/arm-linux-androideabi-gcc-4.8 --sysroot=$SYSROOT" -target \ armv7-none-linux-androideabi \ -gcc-toolchain $NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64" @@ -165,11 +173,11 @@ installation root for the NDK. An example of the use of this script appears belo$NDK/build/tools/make-standalone-toolchain.sh \ ---arch=arm --platform=android-22 --install-dir=/tmp/my-android-toolchain +--arch=arm --platform=android-21 --install-dir=/tmp/my-android-toolchainThis command creates a directory named {@code /tmp/my-android-toolchain/}, containing a copy of -the {@code android-22/arch-arm} sysroot, and of the toolchain binaries for a 32-bit ARM +the {@code android-21/arch-arm} sysroot, and of the toolchain binaries for a 32-bit ARM architecture.
Note that the toolchain binaries do not depend on or contain host-specific paths, in other words, @@ -186,6 +194,14 @@ Table 3 shows the values to use for other toolchains:
Toolchain Value ++ +mips64 compiler +{@code --arch=mips64} ++ mips GCC 4.8 compiler +{@code --arch=mips} +x86 GCC 4.8 compiler {@code --arch=x86} @@ -195,7 +211,7 @@ Table 3 shows the values to use for other toolchains:{@code --arch=x86_64} - @@ -214,34 +230,28 @@ values you can specify for {@code <toolchain>}:MIPS GCC 4.8 compiler +mips GCC 4.8 compiler {@code --arch=mips} arm - {@code --toolchain=arm-linux-android-4.6} -{@code --toolchain=arm-linux-android-4.7} -{@code --toolchain=arm-linux-android-4.8} -{@code --toolchain=arm-linux-android-4.9} -{@code --toolchain=arm-linux-android-clang3.4} +{@code --toolchain=arm-linux-androideabi-4.8} +{@code --toolchain=arm-linux-androideabi-4.9} {@code --toolchain=arm-linux-android-clang3.5} +{@code --toolchain=arm-linux-android-clang3.6} x86 - {@code --toolchain=x86-linux-android-4.6} -{@code --toolchain=x86-linux-android-4.7} {@code --toolchain=x86-linux-android-4.8} {@code --toolchain=x86-linux-android-4.9} -{@code --toolchain=x86-linux-android-clang3.4} {@code --toolchain=x86-linux-android-clang3.5} +{@code --toolchain=x86-linux-android-clang3.6} @@ -249,42 +259,46 @@ values you can specify for {@code <toolchain>}: mips - {@code --toolchain=mips-linux-android-4.6} -{@code --toolchain=mips-linux-android-4.7} {@code --toolchain=mips-linux-android-4.8} {@code --toolchain=mips-linux-android-4.9} -{@code --toolchain=mips-linux-android-clang3.4} {@code --toolchain=mips-linux-android-clang3.5} +{@code --toolchain=mips-linux-android-clang3.6} arm64 {@code --toolchain=aarch64-linux-android-4.9} -{@code --toolchain=aarch64-linux-android-clang3.4} {@code --toolchain=aarch64-linux-android-clang3.5} +{@code --toolchain=aarch64-linux-android-clang3.6} x86_64 {@code --toolchain=x86_64-linux-android-4.9} -{@code --toolchain=x86_64-linux-android-clang3.4} {@code --toolchain=x86_64-linux-android-clang3.5} +{@code --toolchain=x86_64-linux-android-clang3.6} - mips64 {@code --toolchain=mips64el-linux-android-4.9} -{@code --toolchain=mips64el-linux-android-clang3.4} {@code --toolchain=mips64el-linux-android-clang3.5} +{@code --toolchain=mips64el-linux-android-clang3.6} Note: Table 4 is not an exhaustive list. Other combinations may +
Note: Table 4 is not an exhaustive list. Other combinations may also be valid, but are unverified.
-You can also copy Clang/LLVM 3.3, using one of two methods: You can append {@code -clang3.3} to +
You can also copy Clang/LLVM 3.6, using one of two methods: You can append {@code -clang3.6} to the {@code --toolchain} option, so that the {@code --toolchain} option looks like the following example:
---toolchain=arm-linux-androideabi-clang3.3 +--toolchain=arm-linux-androideabi-clang3.6-Alternatively, you can add {@code -llvm-version=3.3} as a separate option on the command +
You can also add {@code -llvm-version=3.6} as a separate option on the command line.
+Note: Instead of specifying a specific version, you can also +use {@code <version>}, which defaults +to the highest available version of Clang.
+By default, the build system builds for a 32-bit host toolchain. You can specify a 64-bit host toolchain instead. Table 5 shows the value to use with {@code -system} for different platforms.
@@ -304,17 +318,21 @@ platforms.64-bit MacOSX {@code -system=darwin-x86_64} ++ -For more information on specifying a 32- or 64-bit instruction host toolchain, see -ndk-build. +For more information on specifying a 64- or 32-bit instruction host toolchain, see +64-Bit and 32-Bit Toolchains. -64-bit Windows +{@code -system=windows-x86_64} +You may specify {@code stl=stlport} to copy {@code libstlport} instead of the default +
You may specify {@code --stl=stlport} to copy {@code libstlport} instead of the default {@code libgnustl}. If you do so, and you wish to link against the shared library, you must explicitly use {@code -lstlport_shared}. This requirement is similar to having to use {@code -lgnustl_shared} for GNU {@code libstdc++}.
-Similarly, you can specify {@code -stl=libc++} to copy the LLVM libc++ headers and libraries. +
Similarly, you can specify {@code --stl=libc++} to copy the LLVM libc++ headers and libraries. To link against the shared library, you must explicitly use -lc++_shared.
You can make these settings directly, as in the following example:
@@ -337,13 +355,13 @@ copy of a C++ STL library, with working exceptions and RTTI support.Working with Clang
You can install Clang binaries in the standalone installation by using the {@code --llvm-version=<version>} option. {@code <version>} is a LLVM/Clang version -number, such as {@code 3.4} or {@code 3.5}. For example: +number, such as {@code 3.5} or {@code 3.6}. For example:
build/tools/make-standalone-toolchain.sh \ --install-dir=/tmp/mydir \ ---toolchain=arm-linux-androideabi-4.7 \ ---llvm-version=3.5 +--toolchain=arm-linux-androideabi-4.8 \ +--llvm-version=3.6Note that Clang binaries are copied along with the GCC ones, because they rely on the same @@ -356,12 +374,12 @@ be able to use them in your own builds by just setting the {@code CC} and {@code variables to point to them.
Invoking Clang
-In an ARM standalone installation built with {@code llvm-version=3.3}, invoking +
In an ARM standalone installation built with {@code llvm-version=3.6}, invoking Clang on a Unix system takes the form of a single line. For instance:
-dirname $0 /clang31 -target armv5te-none-linux-androideabi "$@" +`dirname $0`/clang36 -target armv5te-none-linux-androideabi "$@"@@ -404,7 +422,7 @@ working properly:
clang++invokesclang++31in the same way.
The standalone toolchain includes a copy of a C++ Standard Template Library implementation. This implementation is either for GNU libstdc++, STLport, or libc++, depending on what you specify for the -{@code -stl=<name>} option described previously. To use this implementation of STL, you need +{@code --stl=<name>} option described previously. To use this implementation of STL, you need to link your project with the proper library:
Note: If your project contains multiple shared libraries or