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 Updated to NodeBB v4.3 + New Features

Error: Cannot find -lSDL2

Scheduled Pinned Locked Moved Solved 3rd Party Software
librarysdl2includepath
16 Posts 3 Posters 2.0k Views 1 Watching
  • 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, 07:36

    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!

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 15 Jan 2024, 08:05 last edited by
    #2

    @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

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

    A 1 Reply Last reply 15 Jan 2024, 08:20
    1
    • J jsulm
      15 Jan 2024, 08:05

      @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

      A Offline
      A Offline
      ajcdev
      wrote on 15 Jan 2024, 08:20 last edited by
      #3

      @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 2 Replies Last reply 15 Jan 2024, 08:30
      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 Offline
        J Offline
        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 Offline
            J Offline
            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 Offline
                J Offline
                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 Offline
                        J Offline
                        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 Offline
                              J Offline
                              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

                                11/16

                                15 Jan 2024, 09:44

                                • Login

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