GCC:什么是--start-group和--end-group命令行选项? [英] GCC: what are the --start-group and --end-group command line options?
问题描述
这些命令行选项的目的是什么?请帮助破译以下命令行的含义:
-Wl, - start-group -lmy_lib -lyour_lib -lhis_lib -Wl, - end-group -ltheir_lib
显然它与链接有关,但GNU手册很安静,正是分组意味着什么。
它用于解决几个库之间的循环依赖关系( - (
和 - )
)。 https://stackoverflow.com/questions/45135/linker-order-gcc/409470#409470\">为什么库链接的顺序有时会导致GCC出错?或 man ld
http://linux.die.net/man/1/ld
$ b
- (
档案- 或
- 开始组
档案- 结束-group
档案 d是档案文件的列表。它们可以是显式文件名或-l选项。
重复搜索指定的存档,直到不创建新的未定义的引用。通常情况下,档案只会在命令行中指定的顺序搜索一次。如果需要该存档中的符号来解析由命令行稍后出现的存档中的对象引用的未定义符号,则链接程序将无法解析该引用。通过对档案进行分组,它们都会被重复搜索,直到解决所有可能的引用为止。
使用此选项会产生显着的性能成本。只有在两个或多个档案之间存在不可避免的循环引用时才最好使用它。
因此,组内的库可以几次搜索新符号,并且您不需要丑陋的结构,如 -llib1 -llib2 -llib1
PS归档意味着基本上是一个静态库( *。a
files)
What is the purpose of those command line options? Please help to decipher the meaning of the following command line:
-Wl,--start-group -lmy_lib -lyour_lib -lhis_lib -Wl,--end-group -ltheir_lib
Apparently it has something to do with linking, but the GNU manual is quiet what exactly grouping means.
It is for resolving circular dependences between several libraries (listed between -(
and -)
).
Citing Why does the order in which libraries are linked sometimes cause errors in GCC? or man ld
http://linux.die.net/man/1/ld
-(
archives-)
or--start-group
archives--end-group
The archives should be a list of archive files. They may be either explicit file names, or -l options.
The specified archives are searched repeatedly until no new undefined references are created. Normally, an archive is searched only once in the order that it is specified on the command line. If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on the command line, the linker would not be able to resolve that reference. By grouping the archives, they all be searched repeatedly until all possible references are resolved.
Using this option has a significant performance cost. It is best to use it only when there are unavoidable circular references between two or more archives.
So, libraries inside the group can be searched for new symbols several time, and you need no ugly constructs like -llib1 -llib2 -llib1
PS archive means basically a static library (*.a
files)
这篇关于GCC:什么是--start-group和--end-group命令行选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!