黄石房价:[转]Android编译环境(1) - 编译Native C的模块,Linux技术文章,Linux系列教程,Linux
来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 08:00:29
[转]Android编译环境(1) - 编译Native C的模块
Android编译环境本身比较复杂,且不像普通的编译环境:只有顶层目录下才有Makefile文件,而其他的每个component都使用统一标准的Android.mk. Android.mk文件本身是比较简单的,不过它并不是我们熟悉的Makefile,而是经过了Android自身编译系统的很多处理,因此要真正理清楚其中的联系还比较复杂,不过这种方式的好处在于,编写一个新的Android.mk来给Android增加一个新的Component会比较简单。 编译Java程序可以直接采用Eclipse的集成环境来完成,这里就不重复了。我们主要针对C/C++来说明,下面通过一个小例子来说明,如何在Android 中增加一个C程序的Hello World:
1. 在$(YOUR_ANDROID)/ development 目录下创建hello目录,其中$(YOUR_ANDROID)指Android源代码所在的目录。
- # mkdir $(YOUR_ANDROID)/development/hello
2. 在$(YOUR_ANDROID)/external/hello/目录编写hello.c文件,hello.c的内容当然就是经典的HelloWorld程序:
#include
int main()
{
printf("Hello World!\n");
return 0;
}
3. 在$(YOUR_ANDROID)/external/hello/目录编写Android.mk文件。这是Android Makefile的标准命名,不要更改。Android.mk文件的格式和内容可以参考其他已有的Android.mk文件的写法,针对helloworld程序的Android.mk文件内容如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
hello.c
LOCAL_MODULE := helloworld
include $(BUILD_EXECUTABLE)
注意上面LOCAL_SRC_FILES用来指定源文件;,LOCAL_MODULE指定要编译的模块的名字,下一步骤编译时就要用到;include $(BUILD_EXECUTABLE)表示要编译成一个可执行文件,如果想编译成动态库则可用BUILD_SHARED_LIBRARY,这些可以在$(YOUR_ANDROID)/build/core/config.mk查到。
4. 回到Android源代码顶层目录进行编译:
# cd $(YOUR_ANDROID) && make helloworld
注意make helloworld中的目标名helloworld就是上面Android.mk文件中由LO
CAL_MODULE指定的模块名。编译结果如下:
target thumb C: helloworld <= development/hello/hello.c
target Executable: helloworld (out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld)
target Non-prelinked: helloworld (out/target/product/generic/symbols/system/bin/helloworld)
target Strip: helloworld (out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/helloworld)
Install: out/target/product/generic/system/bin/helloworld
5.如上面的编译结果所示,编译后的可执行文件存放在out/target/product/generic/system/bin/helloworld,通过”adb push”将它传送到模拟器上,再通过”adb shell”登录到模拟器终端,就可以执行了
原文地址 http://www.j2medev.com/android/native/200901/20090119222445.html
Android编译环境本身比较复杂,且不像普通的编译环境:只有顶层目录下才有Makefile文件,而其他的每个component都使用统一标准的Android.mk. Android.mk文件本身是比较简单的,不过它并不是我们熟悉的Makefile,而是经过了Android自身编译系统的很多处理,因此要真正理清楚其中的联系还比较复杂,不过这种方式的好处在于,编写一个新的Android.mk来给Android增加一个新的Component会比较简单。 编译Java程序可以直接采用Eclipse的集成环境来完成,这里就不重复了。我们主要针对C/C++来说明,下面通过一个小例子来说明,如何在Android 中增加一个C程序的Hello World:
1. 在$(YOUR_ANDROID)/ development 目录下创建hello目录,其中$(YOUR_ANDROID)指Android源代码所在的目录。
- # mkdir $(YOUR_ANDROID)/development/hello
2. 在$(YOUR_ANDROID)/external/hello/目录编写hello.c文件,hello.c的内容当然就是经典的HelloWorld程序:
#include
int main()
{
printf("Hello World!\n");
return 0;
}
3. 在$(YOUR_ANDROID)/external/hello/目录编写Android.mk文件。这是Android Makefile的标准命名,不要更改。Android.mk文件的格式和内容可以参考其他已有的Android.mk文件的写法,针对helloworld程序的Android.mk文件内容如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
hello.c
LOCAL_MODULE := helloworld
include $(BUILD_EXECUTABLE)
注意上面LOCAL_SRC_FILES用来指定源文件;,LOCAL_MODULE指定要编译的模块的名字,下一步骤编译时就要用到;include $(BUILD_EXECUTABLE)表示要编译成一个可执行文件,如果想编译成动态库则可用BUILD_SHARED_LIBRARY,这些可以在$(YOUR_ANDROID)/build/core/config.mk查到。
4. 回到Android源代码顶层目录进行编译:
# cd $(YOUR_ANDROID) && make helloworld
注意make helloworld中的目标名helloworld就是上面Android.mk文件中由LO
CAL_MODULE指定的模块名。编译结果如下:
target thumb C: helloworld <= development/hello/hello.c
target Executable: helloworld (out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld)
target Non-prelinked: helloworld (out/target/product/generic/symbols/system/bin/helloworld)
target Strip: helloworld (out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/helloworld)
Install: out/target/product/generic/system/bin/helloworld
5.如上面的编译结果所示,编译后的可执行文件存放在out/target/product/generic/system/bin/helloworld,通过”adb push”将它传送到模拟器上,再通过”adb shell”登录到模拟器终端,就可以执行了
原文地址 http://www.j2medev.com/android/native/200901/20090119222445.html
[转]Android编译环境(1) - 编译Native C的模块,Linux技术文章,Linux系列教程,Linux
Linux apache编译安装
Linux 2.6内核的编译步骤及模块的动态加载 - 内核源码学习 - Linux论坛
arm-linux,arm-elf-交叉编译环境下载地址
Linux下.o,.so,.a,.la文件,Linux技术文章,Linux系列教程,Lin...
Linux怎样编写和编译动态库1
linux下编译和安装log4cxx
实战linux内核编译 - qqread.com
在Linux上交叉编译windows程序
linux 下g++ 编译,中文输入输出
Android编译环境(1)
linux下同时编辑(不是编译哦!)多个c文件命令
linux
开源空间:交叉编译Linux内核(2.6.22.6)-Linux频道-中国IT实验室
android linux 基础知识总结
Android的编译系统
linux模块编程
Linux内核驱动模块
linux-gcc 编译时头文件和库文件搜索路径
Linux Nginx安装编译MySQL 5.1.34扩展库及Php Web服务器
编写最简单的Linux模块
Linux操作系统下以太网卡的安装及配置-Linux教程-Linux系统中文网
Linux 内核使用的 GNU C 扩展
linux下配置jsp环境