版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011337769/article/details/79638634
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 -j4
5.刷机测试
略