1

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
starball
  • 20,030
  • 7
  • 43
  • 238
Ekz
  • 71
  • 7
  • 2
    The error `0xC0000135` means that some `.dll` used by your application cannot be found. Check that directories for all libraries used by your application are listed in `PATH` environment variable. – Tsyvarev Dec 25 '19 at 11:44
  • BTW, in CMake function's arguments are delimited by a **space**, not by the comma (`,`). Your last `message` should be like this: `message(VERBOSE "${SDL2_LIBRARY}")`. (Double quotes make output of elements in the `SDL2_LIBRARY` variable to be delimited by semicolon `;`.) Also, `-lmingw32` has no sense in `CMAKE_CXX_FLAGS` variable: `-l` is a **linker** flag, not a *compiler* one. – Tsyvarev Dec 25 '19 at 11:48
  • Of course I forgot to add sdl.dll... Also fixed those cmake calls you mentioned, thank you! – Ekz Dec 25 '19 at 12:13

2 Answers2

1

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

nonodev96
  • 36
  • 4
1

If the issue is that your DLLs aren't being found at runtime, and you want to copy your SDL DLLs to the same directory, then you can do the following (see also How to copy DLL files into the same folder as the executable using CMake?):

if(WIN32)
  add_custom_command(
    TARGET Test POST_BUILD
    COMMAND "${CMAKE_COMMAND}" -E copy_if_different
      "$<TARGET_FILE:SDL2::SDL2>"
      "$<TARGET_FILE_DIR:yourgame>"
    VERBATIM
  )
endif()

See also:

Also related to this solution: https://github.com/libsdl-org/SDL/issues/6399.

starball
  • 20,030
  • 7
  • 43
  • 238