android2.2下编译c模块
来源:互联网 发布:免费胸卡制作软件 编辑:程序博客网 时间:2024/06/07 10:54
android2.2下编译c模块(原文出处)
Android SDK相当强大和全面了,但有时你的应用程序可能需要更多的功能,需要在android的linux基础层面上运行应用程序。今天研究了如何在android环境下编译c模块,提供以下2种方法:一、使用Android.mk自动编译:
1、在$(yourAndroid)/development目录下,创建一个hello目录。
#mkdir $(yourAndroid)/development/hello
其中$(yourandroid)指android的源代码目录;
2、在hello目录中,编写hello.c,内容如下:
#include <stdio.h>
int main()
{
printf("hello world/n");
exit(0);
//return 0;
}
3、在hello目录中,编写Android.mk, 内容如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := helloworld
LOCAL_SRC_FILES := hello.c
include $(BUILD_EXECUTABLE)
LOCAL_SRC_FILES指定源文件,LOCAL_MODULE指定要编译的模块名,include $(BUILD_EXECUTABLE)指定编译成可执行文件,改为BUILD_SHARED_LIBRARY为动态链接库,这些可参考$(yourAndroid)/build/core/config.mk
4、回到Android源代码顶层目录,进行编译,cd $(your_andoird) && make helloworld
5、#adb push helloworld /data
二、手动编译:
1、编译成目标文件:
#$(yourAndroid)/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gcc -I bionic/libc/arch-arm/include/ -I bionic/libc/include -I bionic/libc/kernel/common -I bionic/libc/kernel/arch-arm -c helloworld.c -o hello.o
2、生成可执行代码:
#$(yourAndroid)/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gcc -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -o helloworld -Lout/target/product/generic/obj/lib -Wl,-rpath-link=out/target/product/generic/obj/lib -lc hello.o -entry=main
3、上传文件:
#adb push helloworld /data
编译好之后,可用file和readelf查看可执行文件。
# file helloworld
helloworld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
#readelf -d helloworld
Dynamic section at offset 0x1000 contains 12 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000004 (HASH) 0x80e8
0x00000005 (STRTAB) 0x8214
0x00000006 (SYMTAB) 0x8134
0x0000000a (STRSZ) 118 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x9088
0x00000002 (PLTRELSZ) 16 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x828c
0x00000000 (NULL) 0x0
这是ARM格式的动态链接可执行文件,运行时需要libc.so和libm.so。"not stripped"表示它还没被STRIP。嵌入式系统中为节省空间通常将编译完成的可执行文件或动态库进行STRIP,即去掉其中多余的符号表信息。在前面"make helloworld showcommands"命令的最后我们也可以看到,Android编译环境中使用了out/host/linux-x86/bin/soslim工具进行STRIP。
备注:在adb shell 终端下运行 ./helloworld如果出现
[1] + Stopped (signal) ./helloworld,
源文件中用exit(0) 替代return 0即可,出现的原因是这个位置的return调用造成栈堆下溢。
参考文摘:
1、http://blog.csdn.net/evilcode/archive/2010/07/14/5733390.aspx2、http://wenku.baidu.com/view/76c618d5360cba1aa811dabd.html~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
****************************************************************************************************************
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- android2.2下编译c模块
- android2.2下编译c模块
- android2.2下编译c模块
- ubuntu下编译android2.2 froyo
- Ubuntu10.10下编译Android2.2平台
- Ubuntu10.10下编译Android2.2内核
- ubuntu下源码编译android2.2
- Ubuntu10.10下编译Android2.2平台
- 编译android2.2
- android2.2源码编译
- android2.2源码编译
- Ubuntu11.04 - 64 bits下编译Android2.2内核
- Fedora13 (DVD版本)下编译 android2.2 的过程
- ubuntu 11.10(32位)下android2.2 源码编译
- Android2.1下调试3G模块(二)
- Android2.1下调试3G模块(二)
- Android2.3在ubuntu下的编译
- ubuntu10.10下编译Android2.3.3源码
- 用缓冲器操纵数据
- Android笔记: ProgressBar 圆形进度条颜色的设置
- 银行们,请进取式应对互联网金融
- 全局思考在程序编写中的重要性
- Struts.xml里的默认属性
- android2.2下编译c模块
- pygame提示没有声卡报错
- c# static的全部用法收集整理(转载)
- php 常用类整理
- 简明VIM使用学习
- Android Push
- 消息内容定义XML
- Property attributes
- 这是我第一篇博文