简体   繁体   English

“计算机缺少SDL2.DLL”,但与程序位于同一文件夹中吗?

[英]“SDL2.DLL missing from computer” but is in the same folder as program?

SDL Folder in the same directory: SDL文件夹在同一目录中:

Contents of SDL folder: SDL文件夹的内容:

I cant get my program to run as it says it cannot find SDL2.DLL? 我无法运行我的程序,因为它说找不到SDL2.DLL? Any ideas? 有任何想法吗?

Programs don't search your entire hard drive for DLLs. 程序不会在整个硬盘上搜索DLL。 That would be expensive, horribly insecure, and bug prone. 那将是昂贵的,非常不安全的,并且容易出错。

Instead they have a search path, which depends on how you load it. 相反,它们具有搜索路径,这取决于您如何加载它。 Often your PATH environment variable is used, together with various other system places, as well as the directory of the process loading the dynamic library. 通常,将PATH环境变量与其他各种系统位置以及加载动态库的进程的目录一起使用。

This list rarely includes "a subdirectory of the process executable called SDL ". 该列表很少包含“进程可执行文件的子目录,称为SDL ”。 You can, however, modify the search path; 但是,您可以修改搜索路径。 how exactly depends on how you are trying to load SDL. 具体取决于您如何尝试加载SDL。

The easy solution is to try to copy them all into the same directory. 一种简单的解决方案是尝试将它们全部复制到同一目录中。

You can use a Post-Build-Event to copy sdl2.dll into the directory where your .exe is built. 您可以使用构建后事件sdl2.dll复制到构建 .exe的目录中。 Manually copying the file is fine for a quick test, but having Visual Studio do it for you has some advantages. 手动复制文件可以进行快速测试,但是使用Visual Studio进行复制有一些好处。 For example, this lets you completely delete your Debug and Release directories and have the correct file copied when you do a clean build. 例如,这使您可以完全删除DebugRelease目录,并在执行干净构建时复制正确的文件。

In your directory listing I see bin32 and bin64 directories inside the SDL directory. 在您的目录列表中,我看到了SDL目录中的bin32bin64目录。 I assume that there is a copy of sdl2.dll directly inside each of those directories, but there are no separate debug and release versions, just 32-bit and 64-bit. 我假设每个目录中sdl2.dll直接包含sdl2.dll的副本,但是没有单独的调试和发行版本,只有32位和64位。 Let me know if this is incorrect, otherwise, you can do this: 如果这不正确,请告诉我,否则,您可以这样做:

Open the Solution Explorer and select your project (not the solution). 打开解决方案资源管理器,然后选择您的项目(不是解决方案)。 Then use Alt+Enter to go directly to the Property Pages. 然后使用Alt + Enter直接转到“属性页”。 (Or right-click the project and select Properties at the bottom of the menu.) (或右键单击该项目,然后在菜单底部选择“ 属性 ”。)

In the selection panel on the left, go to Configuration Properties / Build Events / Post-Build Event . 在左侧的选择面板中,转到“ 配置属性” /“ 构建事件” / “构建后事件”

At the top of the property sheet, set the Configuration dropdown to All Configurations and the Platform dropdown to All Platforms . 在属性表的顶部,将配置下拉菜单设置为所有配置 ,并将平台下拉菜单设置为所有平台

Click the edit box to the right of Command Line and enter this command: 单击命令行右侧的编辑框,然后输入以下命令:

copy "$(SolutionDir)SDL\bin$(PlatformArchitecture)\sdl2.dll" "$(TargetDir)"

Now click OK , and save and build your solution. 现在,单击OK ,然后保存并构建您的解决方案。 You should find that it copies the correct version (32-bit or 64-bit) of sdl2.dll into the build directory. 您应该发现它sdl2.dll的正确版本(32位或64位) sdl2.dll到构建目录中。

The various $(FooBar) entries in the command line are macros which ar automatically expanded according to things like your project directory location, the type of platform you're building for, etc. 命令行中的各种$(FooBar)条目都是宏,它们会根据项目目录位置,要构建的平台类型等自动扩展。

$(SolutionDir) is the directory containing your .sln file, with a trailing backlash . $(SolutionDir)是包含您的目录中.sln文件, 后面带有一个反弹

$(PlatformArchitecture) is 32 or 64 depending on which platform you're building for. $(PlatformArchitecture)3264具体取决于要构建的平台。

$(TargetDir) is the directory that VS creates your .exe file in. $(TargetDir)是VS在其中创建.exe文件的目录。

So this command line is an ordinary copy command as you might use in a command prompt, with the paths filled in to copy either SDL\\bin32\\sdl2.dll or SDL\\bin64\\sdl2.dll to your build target directory. 因此,此命令行是一条普通的copy命令,您可能会在命令提示符中使用该命令,并填充了将SDL\\bin32\\sdl2.dllSDL\\bin64\\sdl2.dll到构建目标目录的SDL\\bin64\\sdl2.dll We use quotes around the source and destination paths in case you have any spaces in your project path. 如果项目路径中有空格,我们会在源路径和目标路径周围使用引号。

In some cases you may need specific commands for a particular configuration (Debug/Release) or platform (Win32/x64). 在某些情况下,您可能需要用于特定配置(Debug / Release)或平台(Win32 / x64)的特定命令。 You can do this by selecting that configuration or platform at the top of the property sheet. 您可以通过在属性表顶部选择该配置或平台来执行此操作。 In our case, we can use one command for both 32-bit and 64-bit builds thanks to the $(PlatformArchitecture) macro. 在我们的例子中,由于有了$(PlatformArchitecture)宏,我们可以对32位和64位版本使用一个命令。

To learn more about the macros, you can select the Command Line box in the property page and then click the drop-down arrow that appears to the right of the box, and select <Edit...> . 要了解有关宏的更多信息,可以在属性页中选择“ 命令行”框,然后单击出现在框右侧的下拉箭头,然后选择<Edit ...> This opens a multiline edit window (you can use more than one command in the build event), with an Evaluated value below it that shows the actual command that will be used for your current configuration and platform. 这将打开一个多行编辑窗口(您可以在build事件中使用多个命令),其下面的一个Evaluated值显示了将用于当前配置和平台的实际命令。 You can inspect this command to see if it looks right, and you can also copy the evaluated command and paste it into a command prompt window for a quick test. 您可以检查此命令以查看它是否正确,还可以复制评估后的命令并将其粘贴到命令提示符窗口中以进行快速测试。

To see a full list of available macros and what they expand to for your current configuration/platform, click the Macros>> button below that and look through the list or use the search box at the top. 要查看可用宏的完整列表以及它们针对当前配置/平台的扩展范围,请单击其下方的“ 宏>>”按钮,然后浏览列表或使用顶部的搜索框。

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

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