10

One can find a lot of examples where QMAKE_LIBDIR is used to specify additional library directories.

The Qt manual says:

QMAKE_LIBDIR

Specifies a list of system library paths. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

Up to now I always used "unix: -L$$(LIB_DIR) -l" or similar whenever I wanted to use an external library in one of my projects and didn't want to use the library wizard.

Can I conclude that specifying a path via -L is discouraged even if there is no corresponding statement within the manual? (According to this post it is discouraged - but why?)

Thanks in advance.

Community
  • 1
  • 1
Apollo13
  • 119
  • 1
  • 1
  • 11

2 Answers2

9

In a way there's a corresponding statement. Put your -Lpath/to/dir into the LIBS variable:

http://doc.qt.io/qt-5/qmake-variable-reference.html#libs

LIBS

Specifies a list of libraries to be linked into the project. If you use the Unix -l (library) and -L (library path) flags, qmake handles the libraries correctly on Windows (that is, passes the full path of the library to the linker). The library must exist for qmake to find the directory where a -l lib is located.

For example:

unix:LIBS += -L/usr/local/lib -lmath

win32:LIBS += c:/mylibs/math.lib

So, using -L within LIBS is actually encouraged by the Qt docs

DomTomCat
  • 8,189
  • 1
  • 49
  • 64
  • May be it'll be useful for someone, but when I added just `win32:LIBS += path/to/lib` I got the error "Permission denied". Adding `-L` before path fixed the problem. – NordMan Jan 26 '23 at 09:49
2

You can set QMAKE_LIBDIR externally without editing of *.pro file unlike from LIBS:

qmake QMAKE_LIBDIR=~/build/obj/

dyomas
  • 700
  • 5
  • 13