Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Error: Cannot find -lSDL2
Forum Update on Monday, May 27th 2025

Error: Cannot find -lSDL2

Scheduled Pinned Locked Moved Solved 3rd Party Software
librarysdl2includepath
16 Posts 3 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A ajcdev
    15 Jan 2024, 08:20

    @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
    
    J Online
    J Online
    jsulm
    Lifetime Qt Champion
    wrote on 15 Jan 2024, 08:30 last edited by
    #4

    @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

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    A 1 Reply Last reply 15 Jan 2024, 08:38
    1
    • J jsulm
      15 Jan 2024, 08:30

      @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

      A Offline
      A Offline
      ajcdev
      wrote on 15 Jan 2024, 08:38 last edited by
      #5

      @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

      J 1 Reply Last reply 15 Jan 2024, 08:41
      0
      • A ajcdev
        15 Jan 2024, 08:38

        @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

        J Online
        J Online
        jsulm
        Lifetime Qt Champion
        wrote on 15 Jan 2024, 08:41 last edited by
        #6

        @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?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply 15 Jan 2024, 08:49
        0
        • J jsulm
          15 Jan 2024, 08:41

          @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?

          A Offline
          A Offline
          ajcdev
          wrote on 15 Jan 2024, 08:49 last edited by
          #7

          @jsulm Yes I am using MinGW compiler. I do apologize since I'm really new when it comes to Qt Creator.

          Also I don't have a .lib file in my SDL2 library and they're all .a files. I downloaded the SDL2 that uses MingW from their repository.

          1 Reply Last reply
          0
          • A ajcdev
            15 Jan 2024, 08:20

            @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
            
            J Online
            J Online
            jsulm
            Lifetime Qt Champion
            wrote on 15 Jan 2024, 09:18 last edited by
            #8

            @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?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply 15 Jan 2024, 09:25
            0
            • J jsulm
              15 Jan 2024, 09:18

              @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?

              A Offline
              A Offline
              ajcdev
              wrote on 15 Jan 2024, 09:25 last edited by
              #9

              @jsulm

              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'
              
              C 1 Reply Last reply 15 Jan 2024, 09:32
              0
              • A ajcdev
                15 Jan 2024, 09:25

                @jsulm

                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'
                
                C Online
                C Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 15 Jan 2024, 09:32 last edited by
                #10

                @ajcdev Since your Qt version is 64bit you must also link against the 64bit sdl lib.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                A 1 Reply Last reply 15 Jan 2024, 09:44
                1
                • C Christian Ehrlicher
                  15 Jan 2024, 09:32

                  @ajcdev Since your Qt version is 64bit you must also link against the 64bit sdl lib.

                  A Offline
                  A Offline
                  ajcdev
                  wrote on 15 Jan 2024, 09:44 last edited by
                  #11

                  @Christian-Ehrlicher I'm not sure how you do that. Do I need to add another library for SDL2 for this?

                  J 1 Reply Last reply 15 Jan 2024, 09:46
                  0
                  • A ajcdev
                    15 Jan 2024, 09:44

                    @Christian-Ehrlicher I'm not sure how you do that. Do I need to add another library for SDL2 for this?

                    J Online
                    J Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on 15 Jan 2024, 09:46 last edited by
                    #12

                    @ajcdev You need to download and use 64bit version of that library. From where exactly did you download it?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    A 1 Reply Last reply 15 Jan 2024, 09:55
                    0
                    • J jsulm
                      15 Jan 2024, 09:46

                      @ajcdev You need to download and use 64bit version of that library. From where exactly did you download it?

                      A Offline
                      A Offline
                      ajcdev
                      wrote on 15 Jan 2024, 09:55 last edited by
                      #13

                      @jsulm I downloaded from their Github Repository.

                      I downloaded the one that comes with the MingW.

                      C J 2 Replies Last reply 15 Jan 2024, 10:01
                      0
                      • A ajcdev
                        15 Jan 2024, 09:55

                        @jsulm I downloaded from their Github Repository.

                        I downloaded the one that comes with the MingW.

                        C Online
                        C Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 15 Jan 2024, 10:01 last edited by
                        #14

                        There is also a64 bit version in the dev zip file. Adjust your path accordingly.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0
                        • A ajcdev
                          15 Jan 2024, 09:55

                          @jsulm I downloaded from their Github Repository.

                          I downloaded the one that comes with the MingW.

                          J Online
                          J Online
                          jsulm
                          Lifetime Qt Champion
                          wrote on 15 Jan 2024, 10:02 last edited by
                          #15

                          @ajcdev Then use the lib in x86_64-w64-mingw32 subfolder. i686-w64-mingw32 is the 32bit version.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          A 1 Reply Last reply 15 Jan 2024, 10:07
                          0
                          • J jsulm
                            15 Jan 2024, 10:02

                            @ajcdev Then use the lib in x86_64-w64-mingw32 subfolder. i686-w64-mingw32 is the 32bit version.

                            A Offline
                            A Offline
                            ajcdev
                            wrote on 15 Jan 2024, 10:07 last edited by
                            #16

                            @jsulm @Christian-Ehrlicher

                            Well, my code doesn't work after but I'll figure it out later.

                            I can say that the linking works properly now. Thanks for your help guys!

                            1 Reply Last reply
                            0
                            • A ajcdev has marked this topic as solved on 15 Jan 2024, 10:07

                            13/16

                            15 Jan 2024, 09:55

                            • Login

                            • Login or register to search.
                            13 out of 16
                            • First post
                              13/16
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved