使用 Android NDK Stand-alone 交叉编译工具

 

使用 Android NDK Stand-alone 交叉编译工具

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值