Search code examples
c++cmakesdlsdl-2clion

CLion, MinGW and SDL2: Process finished with exit code -1073741515 (0xC0000135)


I am trying to add SDL2 to my CLion project. I found this guide and tried to follow it while including only SDL2. Everything compiles, but when I start my app I get "Process finished with exit code -1073741515 (0xC0000135)".

In my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.15)
project(Test)
    
set(CMAKE_CXX_STANDARD 14)
    
set(CMAKE_CXX_FLAGS "-lmingw32 -static-libgcc -static-libstdc++")
set(SDL2_PATH "C:/CPP/libs/SDL2-2.0.10/x86_64-w64-mingw32")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "C:/CPP/libs/CMakeModules")
    
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
    
if (${SDL2_FOUND})
    message(VERBOSE, "sdl found!")
else ()
    message(FATAL_ERROR, "sdl not found")
endif ()
    
message(VERBOSE, ${SDL2_INCLUDE_DIR})
message(VERBOSE, ${SDL2_LIBRARY})
    
add_executable(Test src/main.cpp)
target_link_libraries(Test ${SDL2_LIBRARY})

main.cpp:

#include <SDL.h>
#include <cstdio>

int main(int argc, char *args[]) {

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
    }
    SDL_Quit();
    return 0;
}

I am using CLion 2019.3.2 with bundled CMake, latest MinGW build (x86_64-8.1.0-win32-seh-rt_v6-rev0) and latest SDL2 (2.0.10). CMake output also looks ok:

VERBOSE,sdl found!
VERBOSE,C:/CPP/libs/SDL2-2.0.10/x86_64-w64-mingw32/include/SDL2
VERBOSE,mingw32-mwindowsC:/CPP/libs/SDL2-2.0.10/x86_64-w64-mingw32/lib/libSDL2main.aC:/CPP/libs/SDL2-2.0.10/x86_64-w64-mingw32/lib/libSDL2.dll.a-lpthread

Solution

  • if you are using visual studio toolchains in CLion:

    You need to paste in folder cmake-build-debug or cmake-build-release the files .dll, but no only SDL2_image.dll, all files from folder lib/x86

    SDL2_image-devel-2.0.5-VC.zip