android运行C程序以及C程序在android下的编译
16lz
2022-01-19
在android的设计中,谷歌设计了一套专门为嵌入式设备使用的bionic C库,以替换原有的GUN Libc,这个精简的bionic库据说只有200多K,所以如果只想使用这个精简的C库像在linux下一样 开发C程序,基本是不可能的。当然如果只想让其在shell中运行还是可以做到的。
因为编译完的目标程序是在android下运行,就要使用交叉编译的工具,在下面地址下载:
http://www.codesourcery.com/gnu_toolchains/arm/download.html
下载完之后,bin目录下的arm-none-linux-gnueabi-gcc就是交叉编译器了
? #include int main() { printf ( "nihao a\n" ); printf ( "你好 啊\n" ); return 1; } |
输入一下命令:
./arm-none-linux-gnueabi-gcc hello.c -o hello -static
-static选项在这里是必须的,否则会出现”not found”的错误。
然后就可以把编译好的hello传到手机上运行了。不过这里有个前提条件,要求android机器必须是root过的,好像简单的z4root还不行,必须使用更彻底的root方法,关于如何root,这里就不再赘述了,可以参考相关root的帖子。
adb push hello /dev/sample/
这里要上传的目录必须是root用户所有的。
然后就是运行程序,可以在adb shell里测试
adb shell
cd /dev/sample/
chmod 777 hello
./hello
或者在手机上安装超级终端,在终端里运行
./hello
./hello
更多相关文章
- 从CM刷机过程和原理分析Android系统结构
- 反编译并且修改Android(安卓)APK包
- Android实现pppoe拨号上网(二)具体步骤
- 在android下进行TDD开发
- 反编译并且修改Android(安卓)APK包
- findlibrary returned null产生的联想,Android(安卓)ndk开发打包
- android工程下运行main方法的配置方法
- Android工程的编译过程
- Android从启动到程序运行发生的事情