* arm-linux-androideabi-4.4.3 => targetting ARM-based Android devices
* x86-4.4.3 => targetting x86-based Android devices
* mipsel-linux-android-4.4.3 => targetting MIPS-based Android devices
SYSROOT=$NDK/platforms/android-/arch-/
Where
SYSROOT=$NDK/platforms/android-8/arch-arm
IMPORTANT: Note that only android-9 is supported for the x86 architecture.
Note that android-9 and later are supported for the MIPS architecture.
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:
export CC="$NDK/toolchains/arm-linux-androideabi-4.4.3/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/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.
Note that by default, the ARM-based toolchain will be selected by the script.
Use the '--arch=x86' option to specify the x86-based one,
use the '--arch=mips' option to specify the MIPS-based one, or alternatively '--toolchain=
export PATH=/tmp/my-android-toolchain/bin:$PATH
export CC=arm-linux-androideabi-gcc
Note that without the --install-dir option, make-standalone-toolchain.sh will create a tarball in /tmp/ndk/<toolchain-name>.tar.bz2. This allows you to
archive and redistribute the binaries easily.
Another important benefit is that this standalone toolchain will contain a working copy of the GNU libstdc++, with working exceptions and RTTI support
(as long as you link against libstdc++ or libsupc++)
Use --help for more options and details.
IMPORTANT: The toolchain binaries do not depend or contain host-specific paths, in other words, they can be installed in any location, or even moved if you need to.
NOTE: You can still use the --sysroot option with the new toolchain, but it is now simply optional!
CFLAGS='-march=armv7-a -mfloat-abi=softfp'
Note: The first flag enables Thumb-2 instructions, and the second one enables H/W FPU instructions while ensuring that floating-point
parameters are passed in core registers, which is critical for ABI compatibility. Do *not* use these flags separately!
If you want to use Neon instructions, you will need one more compiler flag:
CFLAGS='-march=armv7-a -mfloat-abi=softfp -mfpu=neon'
Note that this forces the use of VFPv3-D32, as per the ARM specification.
Also, is is *required* to use the following linker flags that routes around a CPU bug in some Cortex-A8 implementations:
LDFLAGS='-Wl,--fix-cortex-a8'
If none of the above makes sense to you, it's probably better not to use the standalone toolchain, and stick to the NDK build system instead, which
will handle all the details for you.
You don't have to use any specific compiler flag when targetting the x86 ABI or the MIPS ABI.
NOTE: There is no plan to support Cygwin / MSys at the moment, but contributions are welcome. Contact the android-ndk forum for details.
NOTE: You will need to explicitly link with libsupc++ if you use these features. To do this, use -lsupc++ when linking binaries, as in:
arm-linux-androideabi-g++ .... -lsupc++
$TOOLCHAIN/arm-linux-androideabi/lib/ for ARM toolchains.
$TOOLCHAIN/i686-linux-android/lib/ for x86 ones.
$TOOLCHAIN/mipsel-linux-android/lib/ for MIPS toolchains.
IMPORTANT: The GNU libstdc++ is licensed under the GPLv3 with a linking exception. See the following URL for details: http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01s02.html
If you cannot comply with its requirements, i.e. you cannot redistribute the shared library, do not use it in your project. The reason the shared version of GNU libstdc++ is not called libstdc++.so is because this would conflict at runtime with the system's own minimal C++ runtime, which is /system/lib/libstdc++.so. This enforces a new name for the GNU ELF library. This is not a problem for the static library.