我试图获得一个我编写并运行的简单SDL2应用程序但是我的计算机上似乎存在SDL2问题。我正在运行64位Windows 8.1 Pro,安装了所有MS Visual Studio C ++ 2013库(x64 和 x86)并且Windows已完全更新。 SDL2在我的旧计算机上运行良好,具有类似的设置(我最近重新安装了Windows),所以我无法解释这个错误。
TL; DR:从C:\ Windows \ System32加载DLL时,我编写的简单测试代码无法加密。如何在Windows上诊断DLL加载问题?
测试代码
#include "SDL.h"
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();
return 0;
}
生成文件
LIBRARY_PATHS=-LC:\MinGW\SDL2-2.0.3\i686-w64-mingw32\lib
LIBRARY_INC=-IC:\MinGW\SDL2-2.0.3\i686-w64-mingw32\include\SDL2
CXX = mingw32-g++
CXXFLAGS=-g
LIBRARY_FLAGS=-lmingw32 -lSDL2main -lSDL2 -mwindows
main.exe: main.cpp
$(CC) $(LIBRARY_PATHS) $(LIBRARY_INC) -o main.exe main.cpp $(LIBRARY_FLAGS)
clean:
rm main.exe
编译并运行
D:\Projects\sdl-test
$ mingw32-make
cc -LC:\MinGW\SDL2-2.0.3\i686-w64-mingw32\lib -IC:\MinGW\SDL2-2.0.3\i686-w64-mingw32\include\SDL2 -o main.exe main.cpp -lmingw32 -lSDL2main -lSDL2
D:\Projects\sdl-test
? gdb .\main.exe
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from D:\Projects\sdl-test\main.exe...done.
(gdb) run
Starting program: D:\Projects\sdl-test/.\main.exe
[New Thread 3136.0xae4]
warning: SHIMVIEW: ShimInfo(Complete)
gdb: unknown target exception 0xc000007b at 0x7758d4f2
During startup program exited with code 0xc000007b.
(gdb) quit
经过大量谷歌搜索后,我发现给出的错误代码(0xc000007b)与加载DLL有关,所以我检查了事件查看器:
事件日志
Event Viewer:
Faulting application name: main.exe, version: 0.0.0.0, time stamp: 0x02d2e568
Faulting module name: ntdll.dll, version: 6.3.9600.17736, time stamp: 0x550f42c2
Exception code: 0xc000007b
Fault offset: 0x0009d4f2
Faulting process id: 0xc40
Faulting application start time: 0x01d0a1729dcec24e
Faulting application path: D:\Projects\sdl-test\main.exe
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
Report Id: db8737d8-0d65-11e5-8268-c4d987e72ee3
Faulting package full name:
Faulting package-relative application ID:
来自另一个日志:
Windows cannot access the file for one of the following reasons: there is a problem with the network connection, the disk that the file is stored on, or the storage drivers installed on this computer; or the disk is missing. Windows closed the program main.exe because of this error.
Program: main.exe
File:
The error value is listed in the Additional Data section.
User Action
1. Open the file again. This situation might be a temporary problem that corrects itself when the program runs again.
2. If the file still cannot be accessed and
- It is on the network, your network administrator should verify that there is not a problem with the network and that the server can be contacted.
- It is on a removable disk, for example, a floppy disk or CD-ROM, verify that the disk is fully inserted into the computer.
3. Check and repair the file system by running CHKDSK. To run CHKDSK, click Start, click Run, type CMD, and then click OK. At the command prompt, type CHKDSK /F, and then press ENTER.
4. If the problem persists, restore the file from a backup copy.
5. Determine whether other files on the same disk can be opened. If not, the disk might be damaged. If it is a hard disk, contact your administrator or computer hardware vendor for further assistance.
Additional Data
Error value: 00000000
Disk type: 0
ntdll.dll是我失去了踪迹的地方;我无法弄清楚为什么我的程序在加载此DLL时崩溃。诸如ProcMon和DependencyWalker之类的程序没有告诉我任何事情,我似乎无法找到关于ntdll.dll做什么或如何解决它的任何官方Microsoft文档。
答案 0 :(得分:1)
知道了!出于某种原因,包括 SDL2.dll , SDL2_image.dll 和 SDL2_ttf.dll 在与正在运行的应用程序相同的文件夹中是不够的。我猜Windows还是找不到它们。我要做的是将 SDL2-2.0.3 \ i686-w64-mingw32 \ bin 的内容复制到 C:\ Windows \ System32 。
我想有更好的方法可以做到这一点;用随机的DLL填充你的windir听起来像是将来弄乱一些东西的好方法,但是现在这个很有用。
答案 1 :(得分:0)
令人惊讶的是,将SDL2放在与main.exe相同的目录中是行不通的。
将SDL2 dll放在与.exe相同的目录中,或将SDL2所在的目录添加到PATH中,或者对于MingW,您可以将LIBRARY_PATH设置为包含dll的目录。