我正在尝试将SDL 2添加到我的CLion项目中。我发现了这个guide,并试图遵循它,同时只包括SDL 2。一切都编译,但当我启动我的应用程序时,我得到“Process finished with exit code -1073741515(0xC 0000135)”。
在我的CMakeLists.txt文件中:
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;
}
我使用CLion 2019.3.2与捆绑的CMake,最新的MinGW构建(x86_64-8.1.0-win32-seh-rt_v6-rev 0)和最新的SDL 2(2.0.10)。CMake输出看起来也正常:
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
3条答案
按热度按时间zlhcx6iw1#
如果您在CLion中使用Visual Studio工具链:
您需要在文件夹
cmake-build-debug
或cmake-build-release
中粘贴文件.dll
,但不仅仅是SDL2_image.dll
,文件夹lib/x86
中的所有文件SDL2_image-devel-2.0.5-VC.zip
ctehm74n2#
如果问题是在运行时找不到您的DLL,并且您希望将SDL DLL复制到同一目录,则可以执行以下操作(另请参见How to copy DLL files into the same folder as the executable using CMake?):
参见:
与此解决方案相关的还有:https://github.com/libsdl-org/SDL/issues/6399。
7eumitmz3#
我的CMakeLists.txt似乎与你的不同。下面是我的配置,希望能对你有所帮助。