SDL2 with Qt6 cmake
Unsolved
General and Desktop
-
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 -
@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?