Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved SDL2 with Qt6 cmake

    General and Desktop
    3
    5
    103
    Loading More Posts
    • 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.
    • S
      Sreedhar last edited by

      Hi,

      I am trying to test SDL2 with Qt 6, but unfortunately getting the below error.

      13:08:08: Running steps for project SDLTest...
      13:08:08: Starting: "E:\Qt\Tools\CMake_64\bin\cmake.exe" --build "F:/Self Learning/QT/Udemy Tutorial/build-SDLTest-Desktop_Qt_6_5_2_MinGW_64_bit-Debug" --target all
      ninja: error: 'SDL2-NOTFOUND', needed by 'CMakeFiles/SDLTest_autogen_timestamp_deps', missing and no known rule to make it
      13:08:09: The process "E:\Qt\Tools\CMake_64\bin\cmake.exe" exited with code 1.
      Error while building/deploying project SDLTest (kit: Desktop Qt 6.5.2 MinGW 64-bit)
      When executing step "Build"
      13:08:09: Elapsed time: 00:00.
      

      My CMakeLists.txt is as below

      cmake_minimum_required(VERSION 3.14)
      
      project(SDLTest LANGUAGES CXX)
      
      set(CMAKE_AUTOUIC ON)
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)
      
      set(CMAKE_CXX_STANDARD 17)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
      find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
      
      
      add_executable(SDLTest
        main.cpp
      )
      
      add_library(SDL2 SHARED IMPORTED)
      set_target_properties(SDL2 PROPERTIES
          IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/lib/SDL2.dll"
          INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/include/SDL2"
      )
      
      target_link_libraries(SDLTest Qt${QT_VERSION_MAJOR}::Core SDL2)
      
      include(GNUInstallDirs)
      install(TARGETS SDLTest
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
          RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
      )
      

      Any help is highly appreciated.

      Regards,
      Sreedhar

      C 2 Replies Last reply Reply Quote 0
      • C
        ChrisW67 @Sreedhar last edited by

        @Sreedhar Nothing really to do with Qt.

        Install SDL and use find_package() in your CMakeLists.txt. See Including SDL in Your Project for two variations.

        S 1 Reply Last reply Reply Quote 2
        • S
          Sreedhar @ChrisW67 last edited by

          @ChrisW67
          Thank you so much.

          I added the below to my cmakelist which solved my issue

          find_package(SDL2)
          
          target_link_libraries(SDLTest2 Qt${QT_VERSION_MAJOR}::Core SDL2::SDL2)
          

          Now I have another problem where the message is

          undefined reference to `WinMain

          if I change main to WinMain then the error get resolved. How do I solve this?

          semlanik 1 Reply Last reply Reply Quote 0
          • semlanik
            semlanik @Sreedhar last edited by semlanik

            @Sreedhar

            Does

            set_target_properties(SDLTest PROPERTIES WIN32_EXECUTABLE TRUE)
            

            help?

            1 Reply Last reply Reply Quote 0
            • C
              ChrisW67 @Sreedhar last edited by

              @Sreedhar I would guess that you need the Qt Gui component and library in order for Qt to provide the main entry point for a Windows GUI application.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post