1

Executing a Windows executable that was compiled with the cc compiler command (compiler installed with Mingw64 MSYS2 on Windows) results in an unexpected error.

I was compiling a slightly modified version of the "smolnes" C program (at https://github.com/binji/smolnes/blob/main/smolnes.cc) with the following command: cc -O2 -Wall smolnes.cc -lSDL2 -g -Wno-parentheses -Wno-misleading-indentation -Wno-bool-operation -shared on Windows 11 with Mingw64 (MSYS2). The modification consisted of removing the J[0]=q=(u*)mmap(0,1<<20,1,1,open(F[1],0),0)+16; line and #include <sys/mman.h> to make it compile on Windows. It compiles as expected, but when running instead of getting the executable to work as normal, it gives me the following error:

Program 'a.exe' failed to run: The specified executable is not a valid
application for this OS platform.At line:1 char:1
+ ./a.exe
+ ~~~~~~~.
At line:1 char:1
+ ./a.exe
+ ~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedExc
   eption
    + FullyQualifiedErrorId : NativeCommandFailed

There is not much information about this error so I couldn't solve it or even know why the error occurs in the first place, which is why I am posting here. Can someone help?

bytebox
  • 11
  • 2
  • `-shared` produces a .dll, not .exe. – HolyBlackCat Oct 30 '22 at 18:43
  • But without `-shared` i get `undefined reference to 'WinMain'` – bytebox Oct 30 '22 at 18:46
  • That's because you don't link SDL2 correctly. Refer to [How do I use SDL2 in my programs correctly?](https://stackoverflow.com/a/64396980/2752075), to the section called "undefined reference to WinMain only". – HolyBlackCat Oct 30 '22 at 18:48
  • Oh... one question though: where do i find the `libSDL2.dll.a` and `libSDL2main.a` files? I cant seem to find them in the release files.. – bytebox Oct 30 '22 at 18:58
  • The same place you found the other `.a` files in (you have to have either `libSDL2.a` or `libSDL2.dll.a` for `-lSDL2` to be accepted in the first place, even if you're getting this error). – HolyBlackCat Oct 30 '22 at 18:59
  • 2
    Thank you very much! The program runs and compiles now without any executable errors. Even though the program doesnt really work, that is outside the scope of my question. – bytebox Oct 30 '22 at 19:12

0 Answers0