gpt4 book ai didi

gcc - 为什么clang选择gcc安装?

转载 作者:行者123 更新时间:2023-12-03 23:55:50 27 4
gpt4 key购买 nike

命令“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?
感谢您的帮助。

编辑:
我在页面上找到了一个可能一般的答案(我使用 Fedora 20)
https://bbs.archlinux.org/viewtopic.php?id=129760

最佳答案

如果此主机有其他默认编译器(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

Toolchains

The gcc driver has no direct understanding of tool chains. Each gcc binary roughly corresponds to the information which is embedded inside a single ToolChain.

The clang driver is intended to be portable and support complex compilation environments. All platform and tool chain specific code should be protected behind either abstract or well defined interfaces (such as whether the platform supports use as a driver driver).

Bind: Tool & Filename Selection. Conceptually, the driver performs a top down matching to assign Action(s) to Tools. The ToolChain is responsible for selecting the tool to perform a particular action; once selected the driver interacts with the tool to see if it can match additional actions (for example, by having an integrated preprocessor).

The driver interacts with a ToolChain to perform the Tool bindings. Each ToolChain contains information about all the tools needed for compilation for a particular architecture, platform, and operating system. A single driver invocation may query multiple ToolChains during one compilation in order to interact with tools for separate architectures.

The results of this stage are not computed directly, but the driver can print the results via the -ccc-print-bindings option. For example:

$ 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"

This shows the tool chain, tool, inputs and outputs which have been bound for this compilation sequence. Here clang is being used to compile t0.c on the i386 architecture and darwin specific versions of the tools are being used to assemble and link the result, but generic gcc versions of the tools are being used on PowerPC.

关于gcc - 为什么clang选择gcc安装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24349124/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com