Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SDL2 with Qt6 cmake
Forum Updated to NodeBB v4.3 + New Features

SDL2 with Qt6 cmake

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 846 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.
  • S Offline
    S Offline
    Sreedhar
    wrote on last edited by
    #1

    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
    0
    • S Sreedhar

      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 Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @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
      2
      • C ChrisW67

        @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 Offline
        S Offline
        Sreedhar
        wrote on last edited by
        #3

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

        semlanikS 1 Reply Last reply
        0
        • S Sreedhar

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

          semlanikS Offline
          semlanikS Offline
          semlanik
          wrote on last edited by semlanik
          #4

          @Sreedhar

          Does

          set_target_properties(SDLTest PROPERTIES WIN32_EXECUTABLE TRUE)
          

          help?

          1 Reply Last reply
          0
          • S Sreedhar

            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 Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

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

            • Login

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