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?

6
  • -shared produces a .dll, not .exe. Commented Oct 30, 2022 at 18:43
  • But without -shared i get undefined reference to 'WinMain' Commented Oct 30, 2022 at 18:46
  • That's because you don't link SDL2 correctly. Refer to How do I use SDL2 in my programs correctly?, to the section called "undefined reference to WinMain only". Commented Oct 30, 2022 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.. Commented Oct 30, 2022 at 18:58
  • 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. Commented Oct 30, 2022 at 19:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.