ARM 版的Clang的使用

安装

android studio下面ndk目录的clang

export PATH="/Users/chennan/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH"

执行命令

预编译

clang -target arm-linux-android21 -E hello.c -o hello.i

预编译的文件,就是将导入的头文件以及宏展开。

编译

clang -target arm-linux-android21 -S hello.i -o hello.s

这一步生成.S的汇编文件

汇编

clang -target arm-linux-android21 -c hello.s -o hello.o

也可以将汇编文件直接编译成可执行文件

clang -target arm-linux-android21 arm_hello.s -o arm_hello

arm_hello.s是hello.s的一个副本,删除了一些伪代码和注释以及对结果影响不大的代码。

链接

有的时候会生成多个o文件,这个时候需要将他们链接起来生成可执行文件

clang -target arm-linux-android21 hello.o -o hello

之后可以将文件push到手机里面执行了。

如果不需要了解中间过程可以执行下面命令,直接生成可执行的文件。

clang -target arm-linux-android21 hello.c -o hello

posted @ 2021-10-09 11:02  公众号python学习开发  阅读(698)  评论(0编辑  收藏  举报