【问题标题】:Why clang selects a gcc installation?为什么clang选择gcc安装?
【发布时间】:2014-06-22 07:38:16
【问题描述】:

命令“clang -v”打印:

$ clang -v
clang version 3.4 (tags/RELEASE_34/final)
Target: i386-redhat-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/4.8.2
Selected GCC installation: /usr/bin/../lib/gcc/i686-redhat-linux/4.8.2

“clang 选择 gcc 安装”是什么意思?为什么? Clang 是否独立于 gcc?
感谢您的帮助。

编辑:
我在页面
https://bbs.archlinux.org/viewtopic.php?id=129760

找到了一个可能是通用的答案(我使用 Fedora 20)

【问题讨论】:

  • Clang 依赖于 libgcc 和 crt 目标文件。当然,它们可以独立构建和安装,但没有规范的方法。

标签: gcc clang


【解决方案1】:

如果此主机有其他默认编译器(Apple 的 OSX/macOS 和 variants of FreeBSD 上默认为 clang),则 Clang 使用主机编译器中的多个设置。获得与其他二进制文件和操作系统库的更多兼容性很有用。

它经常使用主机 binutils(用于链接器和汇编器)、用于 crt 文件和内部编译器头文件的主机编译器和用于 C++ 程序/库中 ABI 兼容性的 c++ 库。

工具链选择是 clang 驱动程序(clang 命令)的一部分,在 https://github.com/llvm-mirror/clang/blob/master/lib/Driver/ToolChains.cpp 文件中实现。

Clang 的“Driver Design & Internals”中有一些文档 http://clang.llvm.org/docs/DriverInternals.html

工具链

gcc 驱动程序对工具链没有直接的了解。每个 gcc 二进制文件大致对应于嵌入在单个 ToolChain 中的信息。

clang 驱动程序旨在可移植并支持复杂的编译环境。所有平台和工具链特定的代码都应该在抽象或明确定义的接口后面进行保护(例如平台是否支持用作驱动程序驱动程序)。

绑定:工具和文件名选择。 从概念上讲,驱动程序执行自上而下的匹配以将操作分配给工具。 ToolChain 负责选择执行特定操作的工具;选择后,驱动程序会与工具进行交互,以查看它是否可以匹配其他操作(例如,通过集成预处理器)。

驱动程序与 ToolChain 交互以执行工具绑定。每个 ToolChain 都包含有关编译特定架构、平台和操作系统所需的所有工具的信息。单个驱动程序调用可能会在一次编译期间查询多个 ToolChain,以便与不同架构的工具进行交互。

此阶段的结果不是直接计算的,但驱动程序可以通过 -ccc-print-bindings 选项打印结果。例如:

$ clang -ccc-print-bindings -arch i386 -arch ppc t0.c
# "i386-apple-darwin9" - "clang", inputs: ["t0.c"], output: "/tmp/cc-Sn4RKF.s"
# "i386-apple-darwin9" - "darwin::Assemble", inputs: ["/tmp/cc-Sn4RKF.s"], output: "/tmp/cc-gvSnbS.o"
# "i386-apple-darwin9" - "darwin::Link", inputs: ["/tmp/cc-gvSnbS.o"], output: "/tmp/cc-jgHQxi.out"
# "ppc-apple-darwin9" - "gcc::Compile", inputs: ["t0.c"], output: "/tmp/cc-Q0bTox.s"
# "ppc-apple-darwin9" - "gcc::Assemble", inputs: ["/tmp/cc-Q0bTox.s"], output: "/tmp/cc-WCdicw.o"
# "ppc-apple-darwin9" - "gcc::Link", inputs: ["/tmp/cc-WCdicw.o"], output: "/tmp/cc-HHBEBh.out"
# "i386-apple-darwin9" - "darwin::Lipo", inputs: ["/tmp/cc-jgHQxi.out", "/tmp/cc-HHBEBh.out"], output: "a.out"

这显示了已为此编译序列绑定的工具链、工具、输入和输出。这里使用 clang 在 i386 架构上编译 t0.c,使用 darwin 特定版本的工具来组装和链接结果,但在 PowerPC 上使用通用 gcc 版本的工具。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-11
    • 1970-01-01
    • 2016-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多