• (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

    
        #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


  • 相关阅读:
    P1001 A+B Problem
    NOIP2015D1T2 信息传递
    海淀区赛游记。。。。
    P3375 【模板】KMP字符串匹配
    Print Article HDU
    BZOJ-2-4870: [Shoi2017]组合数问题 矩阵优化 DP
    BZOJ-1- 4868: [Shoi2017]期末考试-三分
    #6164. 「美团 CodeM 初赛 Round A」数列互质-莫队
    湖南大学第十四届ACM程序设计新生杯(重现赛)
    Codeforces Round #530 (Div. 2)
  • 原文地址:https://www.cnblogs.com/ztguang/p/12647069.html
Copyright © 2020-2023  润新知