[Qbs] GCC: --start-group vs --whole-archive

Christian Gagneraud chgans at gmail.com
Thu May 24 07:12:26 CEST 2018


Hi there,

I'm trying to link internal static libraries to an application, Qbs
made the choice to give the linker command a list of full path to the
library archives.
Because I cannot rely on proper dependency tracking b/w all the static
libraries, I get link errors due to how ld works: it picks up only
unseen symbols as it process the list of archives, which is different
from what msvc does: take all the static libs in a global pool and
make sure nothing is missing.

My list of dependencies is "complete", but libs might have cyclic deps
(!) and i cannot sort out what is the proper link ordering. Both
VisualStudio+msvc and QMake+gcc can deal with that.

I have tried to use the linkWholeArchive this way:
Application {
 name: "Foo"
 Depends { name: "cpp" }
 cpp.linkerFlags: ["-fuse-ld=gold"] // bfd runs out of memory
 files: [ ... ]
 Depends { name: "Qt" ... }
 Depends { name: "Bar"; cpp.linkWholeArchive: true }
 Depends { name: "Baz"; cpp.linkWholeArchive: true }
 // And more ...
}

My static library only declare dependencies on Qt, and they don't use
any "Export".

Qbs generate a command-line using "-Wl,--whole-archive
/path/to/libBar.a /path/to/libBaz.a --no-whole-archive", but the
linker failed with weird messages about both missing symbols and
duplicated symbols.
W/o cpp.linkWholeArchive I get tons of undefined symbols, and I cannot
take the risk to use allowUnresolvedSymbols.

If I copy the generated command in the terminal and replace
--whole-archive with --start-group, and --no-whole-archive with
--end-group, then the link succeed (and is way faster). AFAIU, this
allows GNU ld to behave like msvc.

Another way to get the linkage working is to replace all the
/path/to/libXYZ.a with -L /path/to -l XYZ. This is what qmake is
doing, and again it works well (same codebase). I know that doing that
can cause problems if the linker has the choice of shared and archived
libs, but in my case, "it just works" b/c we only build static
libraries.

Is there a chance i can tweak qbs so that my scenario works?

I'm using custom build of QtCreator-4.6+Qbs-1.11.1, custom build of
Qt-5.6 and distro gcc-5.3, i386/Ubuntu-16.04 docker container on
amd64/Ubuntu-16.04 host.

Thanks,
Chris



More information about the Qbs mailing list