What are the command line options --start-group and -end-group?

What is the purpose of these command line options? Please help decrypt the value of the following command line:

-Wl,--start-group -lmy_lib -lyour_lib -lhis_lib -Wl,--end-group -ltheir_lib 

This seems to have something to do with binding, but the GNU manual is quiet about what grouping means.

+62
gcc linker ld
Apr 13 2018-11-11T00:
source share
1 answer

It is designed to resolve circular dependencies between several libraries (specified between -( and -) ).

Quoting 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 have a list of archive files. They can be either explicit file names or -l.

The specified archives are re-scanned until new undefined links are created. Typically, an archive searches only once in the order in which it is specified on the command line. If the symbol in this archive is necessary to resolve the undefined symbol, which is indicated by the object in the archive, which appears later on the command line, the linker will not be able to resolve this link. Having grouped the archives, all of them will be searched until all possible links are resolved.

Using this option has significant performance. It is better to use it only when there are inevitable circular links between two or more archives.

This way, libraries within a group can look for a few new characters, and you don't need ugly constructs like -llib1 -llib2 -llib1

PS archive means basically a static library ( *.a )

+74
Apr 13 '11 at 15:39
source share



All Articles