问题
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.
回答1:
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
回答2:
You can set QMAKE_LIBDIR
externally without editing of *.pro
file unlike from LIBS
:
qmake QMAKE_LIBDIR=~/build/obj/
来源:https://stackoverflow.com/questions/24511097/qt-qmake-libdir-vs-libs