Compiling C file with MingW in Windows: The system cannot execute the specified program

65 Views Asked by At

The C file compiles perfectly fine as long as it's only:

#include <stdio.h>

int main( void )  {
  printf( "Hello, world without a new line" );
  return 0;
}

and it outputs "Hello, without a new line."

However, as I add more code to my program such as:

printf( "Hello, world with a new line\n" );

and I try to compile it like this:

gcc filename.c -o filename.exe

then I receive the message "The system cannot execute the specified program."

I checked if the PATH in the environment variables is there for MingW/bin, I opened and closed applications if it was a memory issue, I have the McAfee antivirus installed.

2

There are 2 best solutions below

0
Sasanka Deshapriya On BEST ANSWER

This will enable additional warnings which might help identify the issue.

gcc -Wall -Wextra -o filename.exe filename.c

or you can try it disabling your antivirus.

or try with this.

gcc filename.c -o filename
0
Ankit Sahu On

Please try with gcc filename.c without specifying which .exe needs to be created. It will create a.out file and then run this file to get output.