本文介绍了LLVM在Android NDK工具链中的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

Android NDK工具链中的LLVM有什么用途?


简要回顾:

我正在Ubuntu上用Gradlew构建我的本机项目,目标是arm和x86_64体系结构.似乎使用 LLVM 来调用 arm-linux-androideabi-4.9 x86_64 (?)

以下摘录自 armeabi-v7a/ndkBuild_build_output.log:

..,以下内容摘自 x86_64/ndkBuild_build_output.log:

  • "..."表示我修剪过的单行命令的尾巴很长.
  • 个人文件夹的名称&项目已更改.

让我们看一下Android NDK的 toolchains 文件夹中的内容:

myacc:~/.../android-ndk-r17c/toolchains$ tree -L 1
.
├── aarch64-linux-android-4.9
├── arm-linux-androideabi-4.9
├── llvm
├── mips64el-linux-android-4.9
├── mipsel-linux-android-4.9
├── NOTICE-MIPS
├── NOTICE-MIPS64
├── renderscript
├── x86-4.9
└── x86_64-4.9


这让我很困惑.我认为 llvm 是一种工具链,因为它位于此处,与其他工具链相邻.同样,Android NDK工具链中LLVM的实际用途是什么?

感谢您的帮助:)

解决方案

LLVM是编译器(后端).使用的编译器是Clang,位于llvm目录中. (LLVM是执行实际代码生成(又称为后端)的Clang组件的名称.)

以前,NDK使用GCC作为编译器.使用GCC,每个目标体系结构(arm,aarch64,x86等)都有单独的GCC副本,该副本是通过配置该单个目标而构建的.另一方面,Clang/LLVM可以使用一个编译器可执行文件来针对任何已配置的体系结构.因此,使用Clang,您将节省一些磁盘空间,避免拥有许多单独的编译器可执行文件.这就是为什么llvm目录树只有一个副本的原因.

在NDK r17中,您可以同时使用GCC和Clang编译器.默认情况下使用Clang,但GCC仍可用于尚未迁移到使用Clang的项目.在较新的NDK版本中,旧的GCC已删除.

在较新的NDK版本中,即使删除了GCC,仍会保留特定于体系结构的目录,例如aarch64-linux-android-4.9,因为仍使用GNU binutils(构建过程中使用的次要工具),并且这些文件也都包含在其中每个体系结构一个副本(即使从技术上讲它们可以跨体系结构工作).

至于为什么要建造例如手臂还提到了x86_64;当您运行Clang或GCC时,您正在为构建计算机运行一个可执行文件,该可执行文件运行x86_64,因此是路径的prebuilt/linux-x86_64部分.

What's the use of LLVM in Android NDK Toolchains?


A little recap:

I was building my native project with Gradlew on Ubuntu, targeting arm and x86_64 architectures. Seems that LLVM were utilized to call C/C++ compiler of arm-linux-androideabi-4.9 as well as x86_64(?)

The following is extracted from armeabi-v7a/ndkBuild_build_output.log:

..and the following is extracted from x86_64/ndkBuild_build_output.log:

  • The "..." indicates that there's a long tail of this single-line command I've trimmed off.
  • Names of personal folders & project were changed.

Let's take a look what's inside Android NDK's toolchains folder:

myacc:~/.../android-ndk-r17c/toolchains$ tree -L 1
.
├── aarch64-linux-android-4.9
├── arm-linux-androideabi-4.9
├── llvm
├── mips64el-linux-android-4.9
├── mipsel-linux-android-4.9
├── NOTICE-MIPS
├── NOTICE-MIPS64
├── renderscript
├── x86-4.9
└── x86_64-4.9


It's quite confusing to me. I thought llvm is a kind of toolchain since it's placed here, next to other toolchains. Again, what's actually the use of LLVM in Android NDK Toolchains?

Thanks for the help :)

解决方案

LLVM is the compiler (backend). The compiler used is Clang, which resides within the llvm directory. (LLVM is the name of the component of Clang that does the actual code generation, aka backend.)

Previously, the NDK used GCC as compiler. With GCC, each target architecture (arm, aarch64, x86 etc) had a separate copy of GCC built with that individual target configured. Clang/LLVM on the other hand can target any configured architecture with one single compiler executable. So with Clang, you'll save a bit of diskspace, avoiding to have many separate compiler executables. That's why there's only one copy of the llvm directory tree.

In NDK r17, you have both GCC and Clang compilers available; Clang is used by default but GCC is still available for projects that haven't been able to migrate to using Clang yet. In newer NDK versions, the old GCC is removed.

In the newer NDK versions, even if GCC is removed, the architecture specific directories like aarch64-linux-android-4.9 are still kept around, as the GNU binutils (minor tools used by the build process) are still used, and those also come in one copy per architecture (even though they technically might work across architectures).

And as for why building for e.g. arm also mentions x86_64; when you are running Clang or GCC, you are running an executable for your build computer which runs x86_64, hence the prebuilt/linux-x86_64 part of the paths.

这篇关于LLVM在Android NDK工具链中的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:31