您的位置:首页 > 其它

ubuntu下使用NDK编译可执行程序的环境搭建

2018-03-21 13:25 337 查看
1.首先是通过下面链接的高级方法生成自定义编译的工具链
 https://developer.android.google.cn/ndk/guides/standalone_toolchain.html#wwc
2.编写c源码
3.使用下面命令编译arm-linux-androideabi-gcc -o hello hello.c -fPIE -pie --target=mandroid –static或者gedit /etc/profile
#添加环境变量CC
export CC=arm-linux-androideabi-gcc
source
$CC –o hello hello.c -fPIE参考链接:https://www.findhao.net/easycoding/1475

4.接下来生成了arm平台的可执行文件,push到手机执行会报错,error: only position independent executables (PIE) are supported.这是在android L之后linker开启了PIE安全检测,因此需要绕过该机制,程序才能执行
解决办法:https://bbs.pediy.com/thread-213790.htm,该方法不能覆盖linker
则修改源码,通过关键字符串找到源码位置,bionic/linker/linker.cpp



再重新编译源码//初始化编译环境
source build/envsetup.sh
//使用 lunch 命令选择编译目标:
lunch
//使用 make 命令进行构建
make -j45.刷机测试
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: