The -group
options only affect in which libraries/archives (and how many times) the linker will look for symbols to satisfy unresolved references. There's no equivalent of --whole-archive
for dynamic libs, e.g. .so
objects. What you can do is specify --no-as-needed
prior to referencing the library which will force it to be added to the list of needed DSOs for the dynamic linker (see below for an example that uses this technique).
To explain what these are intended for, continuing the linker tradition in which ordering linker flags is of the utmost importance, the --start-group
and --end-group
options establish a bounded range of objects and libraries that will be repeatedly scanned through in order of appearance until none of them contribute any further symbols (or unresolved references, which would necessitate further scanning).
It's commonly used for linking objects which have conplex interdependencies, and/or circular references. An alternative is specifying each object/lib potentially many times, like GCC does when linking to libgcc on this *nix system:
-lgcc --as-needed -lgcc_s --no-as-needed -lc
-lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o
(-lgcc_s
referring to shared-library GCC support routines, e.g., libgcc_s.so.1
, on which libc (-lc
) and libgcc(-lgcc
, a static lib) depend; this creates a cycle requiring another inclusion of -lgcc_s) to resolve new unresolved refs that each object brings with it.
Note that GNU LD (-fuse-ld=bfd
) can handle nested groups, while GNU Gold (-fuse-ld=gold
) cannot. Not sure about LLVM's linker.