(OK) 交叉编译hello.c for android (--sysroot),不使用Android.mk和ndk-build
# export PATH=$PATH:/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/
# arm-linux-androideabi-gcc --sysroot=/opt/android-on-linux/android-ndk-r8e/platforms/android-14/arch-arm/ hello.c -o hello
# adb push hello /data/
# adb shell
执行命令:
chmod 700 /data/hello
/data/hello
+++++++++++++++++++++++++++++++++
# adb push hello /data/data/www/cgi-bin
宿主机浏览器:
http://192.168.0.101:8000/cgi-bin/hello
如果成功的话, 可以看到浏览器上 Hello world!
++++++++++++++++++++++++++++++++++++++++++++++++
[root@localhost 桌面]# gedit readdisk.c
[root@localhost 桌面]# arm-linux-androideabi-gcc --sysroot=/opt/android-on-linux/android-ndk-r8e/platforms/android-14/arch-arm/ readdisk.c -o readdisk
++++++++++++++++++++++++++++++++++++
root@kltexx:/data # ./readdisk
error: only position independent executables (PIE) are supported.
[root@localhost 桌面]# arm-linux-androideabi-gcc --sysroot=/opt/android-on-linux/android-ndk-r8e/platforms/android-14/arch-arm/ -pie -fPIE readdisk.c -o readdisk
阅读(66) | 评论(0) | 转发(0) |
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
# arm-linux-androideabi-gcc --sysroot=/opt/android-on-linux/android-ndk-r8e/platforms/android-14/arch-arm/ hello.c -o hello
# adb push hello /data/
# adb shell
执行命令:
chmod 700 /data/hello
/data/hello
+++++++++++++++++++++++++++++++++
# adb push hello /data/data/www/cgi-bin
宿主机浏览器:
http://192.168.0.101:8000/cgi-bin/hello
如果成功的话, 可以看到浏览器上 Hello world!
++++++++++++++++++++++++++++++++++++++++++++++++
[root@localhost 桌面]# gedit readdisk.c
点击(此处)折叠或打开
-
#include <stdio.h>
-
#include <fcntl.h>
-
-
int main()
-
{
-
unsigned char buf[512];
-
int fd = open("/dev/blk/mmcblk1", O_RDWR);
-
-
printf("文件描述符%d", fd);
-
if (fd < 0) { // printf("%d\n",errno);
-
return 0;
-
}
-
int num;
-
num = read(fd, buf, 512);
-
printf("读取字数%d", num);
-
printf("\n");
-
int i, j;
-
for (i = 0; i < 32; i++) {
-
for (j = 0; j < 16; j++)
-
printf("%02X ", buf[i * 16 + j]);
-
printf("\n");
-
}
-
printf("\n");
-
close(fd);
-
return 0;
- }
[root@localhost 桌面]# arm-linux-androideabi-gcc --sysroot=/opt/android-on-linux/android-ndk-r8e/platforms/android-14/arch-arm/ readdisk.c -o readdisk
++++++++++++++++++++++++++++++++++++
root@kltexx:/data # ./readdisk
error: only position independent executables (PIE) are supported.
[root@localhost 桌面]# arm-linux-androideabi-gcc --sysroot=/opt/android-on-linux/android-ndk-r8e/platforms/android-14/arch-arm/ -pie -fPIE readdisk.c -o readdisk
相关热门文章
给主人留下些什么吧!~~
评论热议