如何调试使用SDL2和SDL2_image用C编写的崩溃的可执行文件(.exe)?如果不可能,是否有办法使其运行?

因此,就像胡说八道,我在Linux中编写了5k行以上的C代码,而没有在任何地方进行交叉编译。 它可以完美地在Linux上编译和运行。

当我尝试在Windows上进行编译时-

gcc main.c -ID:\libraries\SDL2-2.0.8\i686-w64-mingw32\include -LD:\libraries\SDL2-2.0.8\i686-w64-mingw32\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -o experiment.exe

它编译没有错误,但是可执行文件没有运行。崩溃给-

experiment.exe has stopped working

警报框。

有什么我可以调试的吗?还是更好,让它运行?

注意:这些include和lib文件夹也包含SDL2_image中的所有必需文件。在这一点上,我真的不想更改整个游戏库。我想继续使用SDL2。

So far, I've tried the following things -

  1. Try and compile for Windows on Linux using mingw64, gave me a ton of linking errors (not willing to try this again),
  2. Try and use different versions of SDL2 and SDL2_image on Windows

None of which seem to work.

Information:

Compiles and runs on:

Ubuntu Bionic Beaver
SDL2 version: 2.0.8
SDL2_image version: 2.0.3

Compiles but doesn't run on:

Windows 10
SDL version: 2.0.12 | 2.0.8
SDL2_image version: 2.0.5 | 2.0.3

GDB Debug Info:

Program received signal SIGSEGV, Segmentation fault.  
0x6c774dca in SDL_LogCritical () from D:\MinGW\bin\SDL2.dll

This led me to looking into the library itself,

extern DECLSPEC void SDLCALL SDL_LogCritical (int category,
SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);

is the line of code I could find in SDL_log.h. But this is a dead-end.

I have some additional information from compiling with -Xlinker --verbose flag which might not be relevant, but if needed I'll edit in.

Bonus question: If I'm somehow able to get it running on Windows, how do I static compile it? -static flag throws a lot of undefined reference to compile errors.

评论