[Interest] link error (and probably a dumb question)

Andreas Pakulat apaku at gmx.de
Wed Sep 16 14:42:20 CEST 2015


Hi,

On Wed, Sep 16, 2015 at 12:46 PM, René J. V. <rjvbertin at gmail.com> wrote:

> Rainer Wiesenfarth wrote:
>
> > I _think_ that the first command resolves references strictly ordered
> > (Q55Sql first, then Qt5Core) while the second resolves them in common.
> >
> > In this case, using
> >
> >    ... -lQt5Sql -lQt5Core -lQt5Sql ...
> >
> > should solve the issue.
>
> I started trying that, but didn't check all combinations yet. In any case,
> -lQt5Sql -lQt5Core -lQt5Sql -lQt5Core
> doesn't even reduce the number of errors.
>
> I also think that modern linkers no longer have the limitation you refer
> to.


I've only been around for 12 years in the gcc/linux area and the linker
never needed special ordering when linking shared libraries. This has and
is only a requirement when linking against static libraries.

The most common reason for problems when using -l<somelib> along with
-L<somepath-to-the-lib> is that it leaves the linker to decide which
library to actually pick up, while passing the absolute path enforces some
library. Your link command has several -L flags setting up 'search paths'
for the linker and additionally the linker has some built-in paths and a
system may have globally configured ones (/etc/ld.so.config). The linker
will search in these paths in 'some' order for a library named <somelib>.so
and pick the first it finds. I don't remember the order from the top of my
head, but as soon as you have more than one version of a particular
<somelib>.so on your system it may end up picking one that you didn't
intend to. (thats one of the reasons why cmake advertizes passing it
absolute paths to shared libraries and if possible passes these on as-is to
the linker)\

So if you do have another Qt5Core on your system, maybe a slightly
different version, then that would explain the linking errors when you use
just -lQt5Core -lQt5Sql. It also explains possible issues when you use
-lQt5Core /path/to/libQt5Sql.so, since the Qt5Sql is from a different
version of qt it may require other symbols than are in Qt5Core (in
particular if a newer Qt5Sql is used with an older Qt5Core).

The manpage for ld gives some more hints what the search path order is.

Andreas

> > Another guess: Does replacing "-lQt5Core.so" with "-lQt5Core" in the
> > first command change the behavior?
>
> OOps, that was an editing error (my actual paths are more convoluted). So
> that
> actual command was -lQt5Core without the extension (which would fail with
> a "lib
> not found" kind of error).
>
>
> >
> > Best Regards / Mit freundlichen Grüßen
> > Rainer Wiesenfarth
> >
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150916/b7a99937/attachment.html>


More information about the Interest mailing list