简体   繁体   English

找不到 sdl2.dll

[英]Couldn't find sdl2.dll

I'm trying to use sdl2, but when I try to run my program it gives me an error that says我正在尝试使用 sdl2,但是当我尝试运行我的程序时,它给了我一个错误提示

code execution can't proceed because SDL2.dll couldn't be found. try reinstalling [...]

I'm compiling from the terminal, without any IDEs (I'm writing code in Sublime Text).我正在从终端编译,没有任何 IDE(我在 Sublime Text 中编写代码)。 My command looks like this我的命令看起来像这样

g++ src\main.cpp -o ..\..\test.exe -L lib\sdl32\lib -l SDL2 -I lib\sdl32\inc -m32

and my file system like this我的文件系统是这样的

I tried putting the .exe file in the same directory as the lib files, but it doesn't work.我尝试将.exe文件与lib文件放在同一目录中,但它不起作用。

I thought the problem might be that it's looking for SDL2.dll files and all of them are libSDL2.* and I tried changing the file names but it didn't work.我认为问题可能在于它正在寻找SDL2.dll文件并且所有这些文件都是libSDL2.*并且我尝试更改文件名但它没有用。

I also thought the problem was the extension, because they are all in *.dll.a , *.a or *.la , I tried changing that and it didn't work (I also tried a combination of the two).我还认为问题出在扩展名上,因为它们都在*.dll.a*.a*.la ,我尝试更改它但没有奏效(我也尝试了两者的组合)。

This is my main.cpp这是我的main.cpp

#define SDL_MAIN_HANDLED
#include <SDL.h>

int main(int argc, char* argv[]) {
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window* window = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 450, SDL_WINDOW_SHOWN);
    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
    SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);

    SDL_RenderClear(renderer);
    SDL_RenderPresent(renderer);

    SDL_Delay(3000);

    SDL_Quit();
    return 0;
}

Am I missing a file or a compiler flag or something?我是否缺少文件或编译器标志或其他东西?

libSDL2.dll.a is an import library. libSDL2.dll.a是一个导入库。 You use it at compile-time to link the code to load the .dll into your binary.您在编译时使用它来链接代码以将.dll加载到您的二进制文件中。 You will still need to have the SDL2.dll file at runtime which contains the actual implementation.您仍然需要在运行时拥有包含实际实现的SDL2.dll文件。 On Windows, .dll files are searched in the PATH ;在 Windows 上,在PATH中搜索.dll文件; the simplest way to use them is to put them in the directory that contains the executable.使用它们的最简单方法是将它们放在包含可执行文件的目录中。

The .dll file is available for download on the SDL website , you seem to only have the development files. .dll文件可在 SDL 网站上下载,您似乎只有开发文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM