The link issue with SDL2 on macOS

I almost tried every solution on the internet. But CLion keeps failing to link with SDL2.

Here is my cmake file.

However, it keeps saying that

CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find SDL2 (missing: SDL2_LIBRARY)

I installed the SDL2 from homebrew and moved the findsdl2.cmake file to the cmake module path.

Please tell me how to fix it. It has tortured my for a whole night. Thanks a lot.

 

cmake_minimum_required(VERSION 3.15)
project(untitled1)
set(SDL2_PATH "/Users/bluesky/Desktop/sdl2")
find_file(SDL2_INCLUDE_DIR NAME SDL.h HINTS SDL2)
find_library(SDL2_LIBRARY NAME SDL2)
find_package(SDL2 REQUIRED)
add_executable(untitled1 main.cpp)
target_include_directories(untitled1 ${SDL2_INCLUDE_DIR})
target_link_libraries(untitled1 ${SDL2_LIBRARY})

Please sign in to leave a comment.