I've tried compiling an SDL2 program on windows using mingw gcc in Code::Blocks, but the only way I can get the produced binary to work is by stripping the symbols with the -s
option. Even with just a simple printf
program, but only when SDL.h
is included.
What is going wrong and how can I fix it?
Produced output differs depending on how the binary is run.
Using the terminal I get:
Program 'main.exe' failed to run: The specified executable is not a valid application for this OS platform
Using Code::Blocks to build and run, the produced binary runs, but without any output and exits immediately with:
Process terminated with status 32760
Looking up the status code produces no results, both in mingw and SDL2.
Trying to compile with -static
causes a bunch of output with ld returned 1 exit status
and Dwarf Error: Can't find .debug_ranges section
.
This seems to imply that debug info is missing from the linked dll file as I understand it.
SDL2 is included and linked from the extracted SDL2-devel-2.24.0-mingw
folder from the libsdl github releases.
The same errors can be reproduced by creating a SDL2 project with Code::Blocks and compiling the given code in debug and release, since only the release strips the symbols it runs fine, but the debug build does not. Enabling the -s
option in debug produces a working binary.
Edit: Compiling SDL2 from source seems to have fixed the issue, so this seems to only be a problem with the precompiled binaries downloaded from the release page. I'm assuming it was because of the missing debug symbols, but it would be appreciated if anyone can confirm that this was the case and explain why stripping symbols creates a working binary?
Edit 2: The main problem seems to be with the outdated mingw compiler included with Code::Blocks which is on version 8.1.0. Using a more recent version of mingw64 such as 12.2.0 from mingw-w64 also fixes the issue.