Android下使用C语言的四种编译方式
16lz
2022-05-31
一、编写helloworld.c Android.mk
二.编译
ndk-build 命令的使用。
2、使用通用toolchain
arm-none-linux-gnueabi-gcc -static hello.c -o helloworld
adb push helloworld /data
3、在源码环境中编译
在源码development 目录下创建hello目录,将helloworld.c Android.mk拷贝至hello目录下,然后mm即可。
4、使用源码自带Toolchain
在这之前要把上一步中的helloworld模块clean:
make clean-helloworld
使用showcommands选项重新编译helloworld,查看具体命令,从输出命令行可以看到,Android编译环境所用的交叉编译工具链是prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc:
make helloworld showcommands
(target Strip的作用是什么?)
Android并没有采用glibc作为C库,而是采用了Google自己开发的Bionic Libc,通用的Toolchain用来编译和移植Android 的Linux内核是可行的,因为内核并不需要C库,但是开发Android的应用程序时,其他Toolchain编译的应用程序只能采用静态编译的方式才能运行,使用静态方式编译出来的执行文件都比较大。
#include int main() { printf("Hello World!\n"); return 0; } LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:=hello.c LOCAL_MODULE := helloworld LOCAL_MODULE_TAGS := optional include $(BUILD_EXECUTABLE)
二.编译
1、使用NDK r5
ndk-build 命令的使用。
2、使用通用toolchain
arm-none-linux-gnueabi-gcc -static hello.c -o helloworld
adb push helloworld /data
3、在源码环境中编译
在源码development 目录下创建hello目录,将helloworld.c Android.mk拷贝至hello目录下,然后mm即可。
4、使用源码自带Toolchain
在这之前要把上一步中的helloworld模块clean:
make clean-helloworld
使用showcommands选项重新编译helloworld,查看具体命令,从输出命令行可以看到,Android编译环境所用的交叉编译工具链是prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc:
make helloworld showcommands
(target Strip的作用是什么?)
Android并没有采用glibc作为C库,而是采用了Google自己开发的Bionic Libc,通用的Toolchain用来编译和移植Android 的Linux内核是可行的,因为内核并不需要C库,但是开发Android的应用程序时,其他Toolchain编译的应用程序只能采用静态编译的方式才能运行,使用静态方式编译出来的执行文件都比较大。
更多相关文章
- Android(安卓)学习--ListView 的使用(一)
- android源码修改USB权限,去掉USB弹出框
- Android(安卓)SDK 目录和作用的分析详解
- android:shape的使用
- Android(安卓)Studio 使用NDK编译时常见的问题
- android中tabhost的使用
- 箭头函数的基础使用
- NPM 和webpack 的基础使用
- Python list sort方法的具体使用