【发布时间】:2020-07-21 08:37:25
【问题描述】:
我正在尝试使用 SDL2.0 制作程序,但该程序没有显示任何输出并且立即退出。
我正在使用 Windows 10 x64,我在 VSCode 上执行此操作,最新的 CMake 版本。
我实际上尝试了amd64、amd64_x86、x86、x86_amd64 工具链,同样的事情发生了。
一个普通的 hello world 程序运行良好,但在导入 SDL.h 时它什么也不做,没有输出和延迟。
C++ 程序(main.py):
#include "SDL.h"
#include <stdio.h>
int main( int argc, char* args[] )
{
printf("Hi\n");
SDL_Init(SDL_INIT_VIDEO);
SDL_Delay(5 * 1000);
SDL_Quit();
return 0;
}
调试日志时显示“MuserSDL.exe' 已退出,代码为 -1073741515 (0xc0000135)”。 CMake 文件:
cmake_minimum_required(VERSION 3.0.0)
project(MuserSDL VERSION 0.1.0)
include(CTest)
enable_testing()
include_directories(sdl/include)
link_directories(sdl/lib/x64)
message(${PROJECT_SOURCE_DIR})
add_executable(MuserSDL src/main.cpp)
target_link_libraries(MuserSDL SDL2 SDL2main)
target_include_directories(MuserSDL PUBLIC sdl/include)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
tree /a /f 打印的树(缩小版)
C:.
| .gitignore
| CMakeLists.txt
| LICENSE
| README.md
|
+---.vscode
| settings.json
|
+---build (...)
|
+---sdl
| | BUGS.txt
| | ...
| |
| +---docs (...)
| |
| +---include
| | begin_code.h
| | close_code.h
| | SDL.h
| | ...
| |
| \---lib
| +---x64
| | SDL2.dll
| | SDL2.lib
| | SDL2main.lib
| | SDL2test.lib
| |
| \---x86 (...)
|
\---src
main.cpp
【问题讨论】:
-
你的程序可以工作,只是错过了它旁边的 .dll ;) 这就是它一开始就崩溃的原因。
-
@ErwanDaniel 我应该怎么做才能让它找到 .dll?
-
@Qiufeng54321 手工复制就够了。但是使用 CMake 的解决方案是 100% 好的!