I have a code (.c file). And used the following command;

gcc file.c -o file.exe

So when I try to run the .exe file (using Wine) I get an error which says

"wine: Bad EXE format for Z:\home\User\Desktop\file.exe/"

What could the problem be? Just for extra details, I've recently installed Linux and the code i'm trying to run should display some sort of graph/visualization. Is there a software I must download?

  • What are you trying to do? Cross-compile Windows applications on Linux? And what are trying to achieve by this? – phk Dec 5 '16 at 19:41
  • Why are you using Wine??? – Gilles 'SO- stop being evil' Dec 5 '16 at 23:35

gcc makes an executable for the Linux operating system that you are running. Wine runs Windows executables. They are not the same. You can run your executable in the Linux environment, without Wine. By the way, in Linux the custom is for executables to have no suffix such as .exe.

| improve this answer | |
  • BTW gcc can also make executable for other operating system, also .exe format, and also cross-compiling. I remember to have payed with Quake and Doom, both (IIRC) compiled with gcc. Debian had also tools (linker) to compile exe and dll direct in Debian. – Giacomo Catenazzi Dec 5 '16 at 19:41
  • Yes it can but not by running gcc file.c -o file. – AlexP Dec 5 '16 at 19:49


gcc file.c -o a.out

And execute the file as ./a.out

You are building and compiling a file in GNU/Linux, so no need to run it in wine. And in any case you are not compiling the program in .exe format.

Note: I would not call the output file as file because file is also a know linux program, but you would find a better name.

| improve this answer | |
  • Fair point about file, but calling it a.out isn't so constructive, either. Perhaps some advice to change the name of the program (avoiding test.c too...) might be useful. – roaima Dec 5 '16 at 20:53
  • @roaima: why not? a.out is the default, so no conflicts, and I don't need to invent a non-so-useful name (foo/bar/spam/...), but the answer clearly recommend to use a better name. If you can recommend a better name, you (or I) can change the in the example (it really don't matter. This answer answers how to execute a binary (without wine), not about name, nor about suffix .exe which is not effect. – Giacomo Catenazzi Dec 6 '16 at 8:47
  • It it the default, true, but these days a.out makes no obvious sense as a name unless you happen to know that the PDP-7 was very much part of UNIX history. – roaima Dec 6 '16 at 8:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.