- 1 year ago
SDL2d.dll not found on windows with CMake using fetchcontent
The "SDL2d.dll not found" error typically occurs when SDL2d.dll is missing from your system or not in the correct path. If you are using CMake and the fetchcontent
function to download and install SDL2, you can follow these steps to resolve the error:
Check that the
fetchcontent
function is correctly configured to download and install SDL2. Here is an example of how to usefetchcontent
to download and install SDL2:scssinclude(FetchContent)
FetchContent_Declare(
SDL2
URL https://www.libsdl.org/release/SDL2-2.0.16-win32-x64.zip
URL_HASH SHA256=74a4cbbf16f1f4c4a73d72f5ec95652c0527478b7f96783d36c5f1a5a0238d10
)
FetchContent_GetProperties(SDL2)
if(NOT SDL2_POPULATED)
FetchContent_Populate(SDL2)
add_subdirectory(${sdl2_SOURCE_DIR} ${sdl2_BINARY_DIR})
endif()
This code downloads SDL2 from the official website and adds it to your project using
add_subdirectory
.Ensure that the SDL2d.dll file is located in the correct directory. By default, SDL2d.dll is located in the "lib" directory of the SDL2 installation directory. Make sure that this directory is added to the system's PATH environment variable so that the SDL2d.dll file can be found.
Ensure that your CMake project is linking to SDL2d.dll correctly. In your CMakeLists.txt file, you should have a line that looks like this:
scsstarget_link_libraries(${PROJECT_NAME} SDL2d)
This tells CMake to link your project to the SDL2d library. If this line is missing or incorrect, CMake will not be able to find the SDL2d.dll file and you will get the "SDL2d.dll not found" error.
By following these steps, you should be able to resolve the "SDL2d.dll not found" error and use SDL2 with CMake on Windows.