gcc
驱动程序可以使用.specs
文件配置特定的链接器、选项和其他细节(例如覆盖系统头文件)。
当前(截至本文撰写时)GCC版本(4.9.0)的手册在此处描述了Spec文件。
对于Clang / LLVM是否有类似的机制。 显然,Clang也有一个driver概念,但我找不到任何关于Clang是否存在Spec Files或类似机制以及如何使用它们的文档。
我对C和C ++都很感兴趣,但可能指向其中任何一个都会让我开始。
目标是简要介绍覆盖系统头文件和库路径以及链接器。
gcc
驱动程序可以使用.specs
文件配置特定的链接器、选项和其他细节(例如覆盖系统头文件)。
当前(截至本文撰写时)GCC版本(4.9.0)的手册在此处描述了Spec文件。
对于Clang / LLVM是否有类似的机制。 显然,Clang也有一个driver概念,但我找不到任何关于Clang是否存在Spec Files或类似机制以及如何使用它们的文档。
我对C和C ++都很感兴趣,但可能指向其中任何一个都会让我开始。
目标是简要介绍覆盖系统头文件和库路径以及链接器。
可以使用Clang驱动程序没有直接对应“规范(specs)”的功能。大多数嵌入在规范中的功能都在工具特定的参数转换例程中。控制编译流水线的规范部分通常是流水线阶段的一部分。
-nostdinc
和-isystem
来覆盖#include搜索路径。事实证明,现在有一些非常接近规范文件的内容:配置文件。
LLVM 12.x文档的相关摘录(请参见上面的链接):
Another way to specify a configuration file is to encode it in executable name. For example, if the Clang executable is named
armv7l-clang
(it may be a symbolic link toclang
), then Clang will search for filearmv7l.cfg
in the directory where Clang resides.If a driver mode is specified in invocation, Clang tries to find a file specific for the specified mode. For example, if the executable file is named
x86_64-clang-cl
, Clang first looks forx86_64-cl.cfg
and if it is not found, looks forx86_64.cfg
.If the command line contains options that effectively change target architecture (these are
-m32
,-EL
, and some others) and the configuration file starts with an architecture name, Clang tries to load the configuration file for the effective architecture. For example, invocation:x86_64-clang -m32 abc.c
causes Clang search for a file
i368.cfg
first, and if no such file is found, Clang looks for the filex86_64.cfg
.The configuration file consists of command-line options specified on one or more lines. Lines composed of whitespace characters only are ignored as well as lines in which the first non-blank character is
#
. Long options may be split between several lines by a trailing backslash. Here is example of a configuration file:# Several options on line -c --target=x86_64-unknown-linux-gnu # Long option split between lines -I/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../\ include/c++/5.4.0 # other config files may be included @linux.options
Files included by
@file
directives in configuration files are resolved relative to the including file. For example, if a configuration file~/.llvm/target.cfg
contains the directive@os/linux.opts
, the filelinux.opts
is searched for in the directory~/.llvm/os
.
ld
的手册以确定您需要的标志(例如-syslibroot
),并告诉clang通过-Wl
将它们传递给链接器。例如,此命令使我能够使用自定义版本的libstdc ++
:clang++ -std=c++11 -stdlib=libstdc++ -nostdinc++ -isystem/path/to/alt-stdlib/include/c++ -isystem/path/to/alt-stdlib/include/c++/x86_64-apple-darwin14.4.0 -L/path/to/alt-stdlib/lib -lstdc++ -Wl,-syslibroot,/usr/lib -Wl,-syslibroot,/path/to/alt-stdlib/lib test.cpp
- Stuart Berg