Home > OS >  Including library files with qmake without hardcoding the compiler version
Including library files with qmake without hardcoding the compiler version

Time:11-10

When I include an external library using Qt Creator, it adds something like the following to my .pro file:

win32:CONFIG(release, debug|release): LIBS  = -L$$PWD/../../../build-mylibrary-Desktop_Qt_5_15_1_MSVC2019_64bit-Release/mylibrary/release/ -lmylibrary
else:win32:CONFIG(debug, debug|release): LIBS  = -L$$PWD/../../../build-mylibrary-Desktop_Qt_5_15_1_MSVC2019_64bit-Debug/mylibrary/debug/ -lmylibrary
else:unix: LIBS  = -L$$PWD/../../../build-mylibrary-Desktop_Qt_5_15_1_MSVC2019_64bit-Release/mylibrary/ -lmylibrary

INCLUDEPATH  = $$PWD/../../../mylibrary
DEPENDPATH  = $$PWD/../../../mylibrary

The path to the library is specific to the compiler and Qt version. I have several libraries that I would like to distribute. There are various dependencies between them. The libraries can be build by different compilers and different Qt versions. So I don't want to distribute the code with a .pro file that assumes MSVC2019 and Qt 5.15.1 (as in the example above). Is there a standard solution to this problem? Or do I just need to expect people who download the code to change the folder names?

CodePudding user response:

For internal usage, you can use the following qmake variables to dynamically build the libs path (based on the current target):

  • QT_VERSION
  • QMAKE_MSC_VER

For external people, such an approach may not work out of the box, as the build path is configured by the external user, not by the .pro-file.

If your goals is to resolve the linking/include dependencies between your libs, SUBDIRS may be a solution.

Note that qmake is being replaced in favour of cmake. Maybe cmake has a better solution, but I'm not very familiar with it.

CodePudding user response:

A possible solution is to use DESTDIR in your .pro files.

For example:

DESTDIR = ../bin
LIBS *= -L$$OUT_PWD/$$DESTDIR -lmylib
  • Related