Gcc Compiled Binaries Give "Cannot Execute Binary File"

gcc compiled binaries give cannot execute binary file

Take the -c out. That's for making object files, not executables.

g++ compiled binaries give “cannot execute binary file”

This is not a message from your compiler or build-tool, but from your shell and originates from the OS.

For the path /media/, it seems you have your files on external storage e.g. an USB-stick. That might be mounted with option noexec, so you cannot execute from there. Also, if that is VFAT, there are no permission-flags in the, so you cannot set them. Instead default flags are used by the OS and might also prevent execution a program from that partition. This is a security measure against malware.

Try mount and check options.

If I'm right, you should move the files to a normal filesystem, e.g. your home.

Getting the error: bash: (program): cannot execute binary file: Exec format error, on both 32-bit and 64-bit Windows

As indicated by file, your program is a Linux application so you can't run it on Windows. See

  • Why does a linux compiled program not work on Windows
  • Why won't Windows EXE files work on Linux?
  • Why do you need to recompile C/C++ for each OS?

Mingw is not an environment for running Linux executables, it's just a compiler that compiles POSIX code into native Windows binaries. Neither is Cygwin, which is a reimplementation of POSIX system calls in Windows, and Cygwin binaries are also native Windows binaries with a dependency on Cygwin DLLs. Read this if you want to know their differences. Bash is a shell and isn't a platform to execute files either. Only the runtime platform (OS or something like JVM or .NET CLR VM) can run programs and a shell is just a tool to interact with the OS

So you must run Linux programs in a Linux environment like a Linux machine or WSL1/2. Since the program is 32-bit, you can only run it in Linux or WSL2

Since you have the source code you can also compile the code with mingw or cygwin and run on Windows

GNU C Cross-compiler: Cannot execute binary file

This really looks like a kernel that is configured for pure 64-bit userspace, no i386 support.

This would be CONFIG_IA32_EMULATION in the kernel config. Check /proc/config.gz to confirm.

Configuring mingw32 and MSYS (Error executing binaries from /mingw/bin)

Usually, when you encounter cannot execute binary file it's because the exe can't run on your system. Assuming you are on windows, maybe it's because you are using a wrong package of MSYS (and the linux in the tar file seams odd...). Try to get a executable package of MinGW like here and install all the components you want in it. You can follow the tutorial here.

Edited as the right answer.

exe file not found after gcc creates output

Whenever you use a filename as a command, bash will search for it in directorys like /usr/bin. Imagine the situation, in which someone put a executable called ls somewhere unprotected on your computer. Like @some programmer dude pointed out, you habe to explicitly specify the path to your executable. This path can be relative (./simplify.exe) or absolute (/home/username/projects/simplify/simplify.exe).

By the way, on linux systems it is umcommon to use a file ending, espacially ".exe". If you want to use one, I recommend ".elf", which stands for "executable linkable file". (You can do so much more than EXEcuting a file - and down we go the rabbit hole)

My C program fails to run with `cannot execute binary file: Exec format error`

Ok since no one wants wanted to say why... you need to remove the -c option because according to the man:

the -c option says not to run the linker. Then the output consists of object files output by the assembler.

So basically, you are not creating a fully executable file, just object files.

Here's some quick info on how compiling works: http://courses.cms.caltech.edu/cs11/material/c/mike/misc/compiling_c.html

Exec format error 32-bit executable Windows Subsystem for Linux?

32-bit ELF support isn't provided by WSL (yet). There doesn't seem to be any progress since the UserVoice was raised - you are out luck.

See UserVoice: Please add 32 bit ELF support to the kernel and Support for 32-bit i386 ELF binaries.

If possible, switch to a real Linux ;-)


Since this was originally posted, the support has been available on WSL2 which does support real Linux kernel! So that should be the preferred way.

As noted in the linked github issue, there's also qemu-user which can be used if WSL1 is still used.



Related Topics



Leave a reply



Submit