Error: Cannot find -lSDL2
-
Hello.
I need help regarding my issue trying to link SDL2 in my project and for some reason it's getting errors although I just followed this guide.
This is my code after linking my SDL2 library and include:
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ aerodesk.cpp HEADERS += \ aerodesk.h FORMS += \ aerodesk.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../SDL2-2.28.5/i686-w64-mingw32/release/ -lSDL2 else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../SDL2-2.28.5/i686-w64-mingw32/debug/ -lSDL2 else:unix: LIBS += -L$$PWD/../../SDL2-2.28.5/i686-w64-mingw32/ -lSDL2 INCLUDEPATH += $$PWD/../../SDL2-2.28.5/i686-w64-mingw32/include/SDL2 DEPENDPATH += $$PWD/../../SDL2-2.28.5/i686-w64-mingw32/include/SDL2
The errors are following below:
:-1: error: cannot find -lSDL2 :-1: error: collect2.exe: error: ld returned 1 exit status :-1: error: [Makefile.Debug:72: debug/AeroDesk.exe] Error 1
Any help is appreciated!
-
@ajcdev Was the SDL lib built using same compiler you're using?
Also, on Windows your LIBS should look differently, see https://doc.qt.io/qt-6/qmake-variable-reference.html#libs -
@jsulm No. I just downloaded the SDL2 from their Github repository.
This is what I have done so far. Now it can't detect the SDL2 library itself:
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ aerodesk.cpp HEADERS += \ aerodesk.h FORMS += \ aerodesk.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target win32:LIBS += "C:\Users\admin\Documents\SDL2-2.28.5\i686-w64-mingw32\lib\libSDL2.a" INCLUDEPATH += $$PWD/../../SDL2-2.28.5/i686-w64-mingw32/include/SDL2 DEPENDPATH += $$PWD/../../SDL2-2.28.5/i686-w64-mingw32/include/SDL2
-
@ajcdev said in Error: Cannot find -lSDL2:
win32:LIBS += "C:\Users\admin\Documents\SDL2-2.28.5\i686-w64-mingw32\lib\libSDL2.a"
This is for static library. Do you want to link dynamically? If so, then you have to add *.lib, not *.a
-
@jsulm Yeah I want to link dynamically.
I tried this:
win32:LIBS += C:\Users\admin\Documents\SDL2-2.28.5\i686-w64-mingw32\lib\*.lib
Now the error is this:
:-1: error: cannot find C:\Users\admin\Documents\SDL2-2.28.5\i686-w64-mingw32\lib*.lib: Invalid argument
-
@ajcdev said in Error: Cannot find -lSDL2:
win32:LIBS += C:\Users\admin\Documents\SDL2-2.28.5\i686-w64-mingw32\lib*.lib
What is this please?! You have to put the file name of your library instead of *.lib...
Are you using MinGW compiler?
-
-
@ajcdev said in Error: Cannot find -lSDL2:
Now it can't detect the SDL2 library itself
What does this mean? What exactly happens if you try to link the static version?
-
win32:LIBS += "C:\Users\admin\Documents\SDL2-2.28.5\i686-w64-mingw32\lib\libSDL2.a"
So this is what I used since there's no .lib files in the SDL2 MingW library. What happens is that my SDL2 codes get an error that they become undefined.
aerodesk.cpp:16: error: undefined reference to `SDL_Init'
-
@ajcdev Since your Qt version is 64bit you must also link against the 64bit sdl lib.
-
@Christian-Ehrlicher I'm not sure how you do that. Do I need to add another library for SDL2 for this?
-
There is also a64 bit version in the dev zip file. Adjust your path accordingly.
-