(OK) 在Android系统上运行C/C++程序

http://blog.chinaunix.net/uid-14735472-id-5214306.html

# 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


#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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值