0

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.

AnonZX
  • 31
  • 3
  • How did you install MinGW? – HolyBlackCat Aug 30 '22 at 17:36
  • @HolyBlackCat I used the binaries included with the portable Code::Blocks zip file to keep everything portable, I don't really use Windows regularly and wanted an easy way to compile some code I've written in Linux without cross compiling. Don't know whether this type of setup could have caused this? – AnonZX Aug 30 '22 at 17:52
  • What does `g++ --version` say? I would try GCC from [MSYS2](https://stackoverflow.com/q/30069830/2752075). – HolyBlackCat Aug 30 '22 at 18:01
  • gcc and g++ version is 8.1.0, both gave the same error with the precompied binaries, which was downloaded with the latest version of Code::Blocks. I'll try compiling with a newer version and see what happens. – AnonZX Aug 30 '22 at 18:07
  • @HolyBlackCat Compiling with mingw64 version 12.2.0 fixes the problem, so it seems like the main cause was the outdated version of mingw included with Code::Blocks. I'm surprised I didn't think about checking the version earlier, but this helps explain a lot. And I should probably avoid using Code::Blocks for future projects then. – AnonZX Aug 30 '22 at 18:26
  • CB can be used with an updated compiler, but last time I checked, it was a poor IDE for other reasons. Consider VSC (w/ Clangd plugin for code completion). – HolyBlackCat Aug 30 '22 at 18:28

0 Answers0