Nominate our 2022 Qt Champions!

Ubuntu 10.10, Qt installed under /usr, and qmake adding -L/usr/lib

  • Hi,

    I'm completely new to Qt and qmake. I am trying to build a Qt application that uses a locally patched version of a shared system library. Since qmake automagically adds the -L$PREFIX/lib to the link line (LIBS), I get problems when I later define my own -L/some/place/in/ld_library_path/ -lfoo, since /usr/lib also contains

    The problem, as I see it, is that libraries that reside in "trusted" locations (/usr/lib and /lib) are automatically added to the run-time linker, and should therefore not be added to the LIBS line by qmake. It does make sense to add the -L$PREFIX/lib in those cases when the qt libraries are installed outside the trusted directories (and perhaps also not listed in /etc/

    My question is pretty simple; is there a fix to this problem, not relying creating "hacks" in the filesystem (soft links and library renames)? A way to force qmake to not add /usr/lib to the linker would be the preferred solution here.


  • Not sure I understand exactly what you want to do, but have you tried setting / resetting any of the other qmake variables related to library directories? For example, if /usr/lib is added because that is where the Qt libraries are, you could try to just reset QMAKE_LIBDIR_QT:
    Or remove /usr/lib explicitly:
    @QMAKE_LIBDIR_QT -= /usr/lib@
    Or, if you want to add your own directory /some/place before /usr/lib, you could do
    @QMAKE_LIBDIR_QT = /some/place $$QMAKE_LIBDIR_QT@

  • $ mkdir test
    $ cd test/
    $ touch main.cpp
    $ qmake -project
    $ qmake
    $ grep LIBS Makefile | head -1
    LIBS = $(SUBLIBS) -L/usr/lib -lQtGui -lQtCore -lpthread

    QMAKE_LIBDIR_QT -= /usr/lib
    to solves the problem. Thanks! I still think that the presence of -L/usr/lib is dubious behaviour, but this is perhaps something to talk to the ubuntu package maintainer about, and not this forum.

    Anyway, thanks for helping a rookie :)


Log in to reply