NDK r5 正式支持作为独立的交叉编译toolchain(不必依靠Android Make 系统),参考android-ndk-r5/docs/STANDALONE-TOOLCHAIN.html
gcc 目录相关选项参考:http://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html
shared library参考:http://ehuss.net/shared/
1: Source Code => Executable Binary
------------------------------------------------------
$ export NDK=$HOME/android/android-ndk-r5
$ export CC=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
$ export SYSROOT=$NDK/platforms/android-4/arch-arm
$ $CC --sysroot=$SYSROOT -o hello hello.c
关于--sysroot=dir:Use dir as the logical root directory for headers and libraries. For example, if the compiler would normally search for headers in /usr/include and libraries in /usr/lib, it will instead search dir/usr/include and dir/usr/lib
2: Shared Library(.so)
----------------------------
$ $CC --sysroot=$SYSROOT -fPIC -c hello_lib.c
$ $CC --sysroot=$SYSROOT -shared -o libhello_lib.so hello_lib.o
$ $CC --sysroot=$SYSROOT -L. -lhello_lib -o hello hello.c
关于-Ldir:Add directory dir to the list of directories to be searched for -l
关于-llibrary:Search the library named library when linking
No comments:
Post a Comment