zoukankan      html  css  js  c++  java
  • (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
    ",errno);
            return 0;
        }
        int num;
        num = read(fd, buf, 512);
        printf("读取字数%d", num);
        printf("
    ");
        int i, j;
        for (i = 0; i < 32; i++) {
            for (j = 0; j < 16; j++)
                printf("%02X ", buf[i * 16 + j]);
            printf("
    ");
        }
        printf("
    ");
        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



  • 相关阅读:
    非foreach情况下取某一节点的position()
    MorningSale 介绍
    XSLT中的内容自动换列
    十年相伴一首歌
    Navicat的强大自动定时备份
    Xshell6评估期已过的解决方法
    Ext JS继承: 关于object, constructor和prototype
    WCF+Silverlight 异常处理
    Adding/removing fields and columns drag & drop bug's fix
    WCF部署至IIS问题二则
  • 原文地址:https://www.cnblogs.com/ztguang/p/12647146.html
Copyright © 2011-2022 走看看