Firefly开源社区

标题: [小记]anroid下直接运行C程序 [打印本页]

作者: qingfeng623    时间: 2016-5-20 11:02
标题: [小记]anroid下直接运行C程序
1,编辑一个简单的C程序,如:hello world
#include <stdio.h>
int main() {
    printf("hello world\n");


    return 0;
}
hello.c


2,使用交叉编译工具进行编译
/opt/gcc-linaro-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc hello.c -o hello -static
-static选项在这里是必须的,否则会出现”not found”的错误。
然后就可以把编译好的hello传到手机上运行了。不过这里有个前提条件,要求android机器必须是root过的,好像简单的z4root还不行,必须使用更彻底的root方法,关于如何root,这里就不再赘述了,可以参考相关root的帖子。


3,把hello发送到android设备
    a,可以使用adb push把hello发送到设备上
    b,可以通过U盘,把hello拷贝到设备上。(具体过程可能需要参考另一篇挂载U盘的帖子)


4,adb shell,登陆到设备上
找到hello文件,./hello执行即可


作者: pqy    时间: 2016-5-20 12:46
并非如此,就算没有root,就算没有加-static(也就是用动态编译),也可以跑。
例如apktool手机版,就成功把动态编译的openjdk移植到了安卓上。
作者: qingfeng623    时间: 2016-5-23 10:30
pqy 发表于 2016-5-20 12:46
并非如此,就算没有root,就算没有加-static(也就是用动态编译),也可以跑。
例如apktool手机版,就成功 ...

我编译出来的hello,就必须root,还再加-static才能用。你说的这个,我没有遇到过。多谢补充。:handshake




欢迎光临 Firefly开源社区 (https://dev.t-firefly.com/) Powered by Discuz! X3.1