gpt4 book ai didi

c++ - 使用 SDL2 和 MinGW 诊断 DLL 问题

转载 作者:可可西里 更新时间:2023-11-01 10:35:22 27 4
gpt4 key购买 nike

我正在尝试让我编写并运行一个简单的 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 官方文档。

最佳答案

明白了!由于某些原因,将 SDL2.dllSDL2_image.dllSDL2_ttf.dll 包含在与正在运行的应用程序相同的文件夹中是不够的。我猜 Windows 仍然找不到它们。我要做的是将 SDL2-2.0.3\i686-w64-mingw32\bin 的内容复制到 C:\Windows\System32

我想有更好的方法可以做到这一点;用随机 DLL 填充你的 windir 听起来是一个很好的方式来搞砸 future 的事情,但现在这行得通。

关于c++ - 使用 SDL2 和 MinGW 诊断 DLL 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30699502/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com