0

I downloaded SDL2 release edition from: sdl-github: SDL2-devel-2.24.0-mingw.zip.

The OS is windows 10. Compile environment is MINGW64. IDE is clion.

My CMakeLists.txt file is

cmake_minimum_required(VERSION 3.20)
project(sdl_test)

set(CMAKE_CXX_STANDARD 20)

list(APPEND CMAKE_PREFIX_PATH "D:/lib/SDL2-2.24.0")

MESSAGE(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")

find_package(sdl2 CONFIG REQUIRED)
MESSAGE(STATUS "SDL2_INCLUDE_DIRS is ${SDL2_INCLUDE_DIRS}")
MESSAGE(STATUS "SDL2_LIBRARIES is ${SDL2_LIBRARIES}")

include_directories(${SDL2_INCLUDE_DIRS})
add_executable(sdl_test main.cpp)
target_link_libraries(sdl_test ${SDL2_LIBRARIES}-static)
target_link_libraries(sdl_test ${SDL2_LIBRARIES}main)

The main.cpp file is:

extern "C"{
#include <SDL.h>
};
#include <stdio.h>

int main(int argc, char* argv[])
{
    SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);
    printf("SDL initialize ok!");
    SDL_Quit();
    getchar();
    return 0;
}

The program can be compiled with no errors but when running it turns that: runnerw.exe: CreateProcess failed with error 193: %1

Haibaicai
  • 11
  • 2
  • The error means that the executable cannot be run: https://stackoverflow.com/a/12637373/3440745. Most likely, the reason is not finding the SDL dlls. You need to add path to that dlls to the PATH variable. – Tsyvarev Sep 24 '22 at 17:13
  • Try running the exe by double-clicking it in the explorer, see if you get a better error message. – HolyBlackCat Sep 24 '22 at 18:23
  • I have `SDL2.dll` in the same directory as where the `main.exe` is. And I think `target_link_libraries(sdl_test ${SDL2_LIBRARIES}-static)` means a static link (right?). But when I add DLL path to PATH and reboot the system, things seems goes well. – Haibaicai Sep 24 '22 at 18:34

0 Answers0