0

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

#!/bin/bash
#
gcc file.c -o file.exe
#./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?

closed as unclear what you're asking by Stephen Kitt, Jeff Schaller, GAD3R, techraf, HalosGhost Dec 9 '16 at 21:34

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 Dec 5 '16 at 23:35
2

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.

  • 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
0

Use

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.

  • 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.