Qt - QMAKE_LIBDIR vs LIBS

天大地大妈咪最大 提交于 2019-12-12 07:58:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!