Unzip the NDK package into the system, such as the/mnt directory, and then create the folder My_ndk_toolchain under the/mnt directory, and then execute the following command in the/MNT directory:
/mnt/android-ndk-r9c/build/tools/make-standalone-toolchain.sh--platform=android-19--toolchain=arm-linux-androideabi-4.8--stl=stlport--install-dir=/mnt/my_ndk_toolchain
The following print appears:
Dir=/mnt/my_ndk_toolchain
Copying prebuilt binaries ...
Copying sysroot Headers and libraries ...
Copying libstdc++ Headers and libraries ...
Copying files to:/mnt/my_ndk_toolchain
Cleaning up ...
Done.
Explains the success of the standalone toolchain and simply explains the commands executed:
/mnt/android-ndk-r9c/build/tools/make-standalone-toolchain.sh: Execute make-standalone-toolchain.sh script under NDK directory;
--platform: Refers to which version of the Android API the toolchain will use, can be viewed in cd/mnt/android-ndk-r9c/platform, I use Android-19;
--toolchain: Refers to the independent tool chain which uses the compiler, ARM (arm-linux-androideabi-4.8), X86 (x86-4.8) or MIPS (mipsel-linux-android-4.8), CD Toolchains to view and select the appropriate type, I use the embedded;
--stl: Refers to the tool chain support C + + Stl,stlport representative C + + library will be static link, stlport_shared will dynamically link;
--install-dir: Refers to the installation directory;
Note: Because I am using 32-bit Ubuntu, the standalone tool chain is 32 bits by default, so there is no system type specified in the parameters, and if it is a 64-bit Linux system, add--system=linux-x86_64 or MacOSX to join--system= Darwin-x86_64.
Hello.cpp
#include <iostream>
#include <string>
int main (int argc, char **argv)
{
std::string str = "Hello, ndk! This is my own toolchain! ^-^";
std::cout << str << Std::endl;
return 0;
}
Makefile
rm=/bin/rm-f
cc=/mnt/my_ndk_toolchain/bin/arm-linux-androideabi-g++
Progname = Main
includes=-I.
CFLAGS = $ (includes)-g-fpic-d_file_offset_bits=64-d_large_file
Objs = hello.o< Br>ldflags =
All: $ (progname)
%.O:%.cpp
$ (CC) $ (CFLAGS)-c-o [email protected ] $<
$ (Progname): $ (OBJS)
@echo "linking $ (progname) ..."
${CC} ${ldflags}-o ${progname} ${objs}
@echo "Linking success!"
Clean:
$ (RM) *.O $ (progname)
After compiling the executable file: MAIN,ADB push to the embedded Android platform after the./main run, the following results are obtained:
[Email protected]:/data #./main
Hello, ndk!. This is my own toolchain! ^-^
Generate a customized Android toolchain installation that Includesa working sysroot. The result is something this can more easily beused as a standalone cross-compiler, e.g. to run configure Andmake scripts. Valid Options (defaults is in brackets):--help Print this help. --verbose Enable verbose mode. --dryrun Set to Dryrun mode. --toolchain=<name> Specify Toolchain name--USE-LLVM use LLVM. --stl=<name> Specify C + + stl [GNUSTL]--arch=<name> Specify target architecture--abi S=<list> Specify list of target ABIs. --ndk-dir=<path> take source files from NDK at <path> [.] --package-dir=<path> Place package file in <path> [/tmp/ndk-root]--install-dir=<path> Don t CR Eate package, install files to <path> instead. --platform=<name> Specify target Android platform/api level. [Android-3]
To extract the NDK's toolchain and use it alone.