(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


posted @   张同光  阅读(202)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示