Adding all external libraries stored in a directory to a Qt project

Is there a way to add all the libraries from this folder without adding each of them to a variable LIBSin the Qt project file.

I put all the libraries (DLL (win) or SO (unix)) in one directory (MYLIBS) along with the header files and tried something like this:

LIBS *= -L$$PWD/MYLIBS -l*
INCLUDEPATH += $$PWD/MYLIBS
DEPENDPATH += $$PWD/MYLIBS

It did not work with the error message cannot find -l*. Is it possible to use qmakewildcards when creating makefiles?

+4
source share
1 answer

files, basename replace, , :

LIBS *= -L$$PWD/MYLIBS
win32 {
    SHARED_LIB_FILES = $$files($$PWD/MYLIBS/*.dll)
    for(FILE, SHARED_LIB_FILES) {
        BASENAME = $$basename(FILE)
        LIBS += -l$$replace(BASENAME,.dll,)
    }
}
unix {
    SHARED_LIB_FILES = $$files($$PWD/MYLIBS/*.so)
    for(FILE, SHARED_LIB_FILES) {
        BASENAME = $$basename(FILE)
        LIBS += -l$$replace(BASENAME,.so,)
    }
}
+7

Source: https://habr.com/ru/post/1547611/


All Articles