ARM 版的Clang的使用


安装

android studio下面ndk目录的clang

export PATH="/Users/chennan/Library/Android/sdk/ndk/21.3.6528147/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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM