[Qbs] GCC: --start-group vs --whole-archive
Christian Kandeler
christian.kandeler at qt.io
Thu May 24 10:39:13 CEST 2018
On Thu, 24 May 2018 17:12:26 +1200
Christian Gagneraud <chgans at gmail.com> wrote:
> 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.
Why do they have cyclic dependencies? Did you design them this way?
> Both VisualStudio+msvc and QMake+gcc can deal with that.
And qbs + msvc, I would assume?
> 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.
What kind of symbols are these?
> 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.
In which version of your command line did you do that change? The one with --whole-archive?
> Is there a chance i can tweak qbs so that my scenario works?
If you really have cyclic dependencies between your libraries, then obviously that defeats the whole dependency management approach. In such a case, you'll probably have to go with manually specifying the libraries using cpp.linkerFlags, including --start-group and --end-group.
Christian
More information about the Qbs
mailing list