gcc on Windows: generated "a.exe" file vanishes

mingw
gcc windows
gcc options
gcc tutorial
gcc c++
mingw installation manager
c compiler for windows
g++ compiler

I'm using GCC version 4.7.1, but I've also tried this on GCC 4.8. Here is the code I'm trying to compile:

#include <stdio.h>

void print(int amount) {
    int i;
    for (i = 0; i < 5; i++) {
        printf("%d", i);
    }
}

int main(int argc, char** argv) {
    print(5);
    return 0;
}

It looks like it should work, and when I compile with...

gcc main.c

It takes a while to compile, produces an a.exe file and the the a.exe file disappears. It isn't giving me any errors with my code.

Here's a gif of proof, as some people are misinterpreting this:

(Since ahoffer's deleted answer isn't quite correct, I'll post this, based on information in the comments.)

On Windows, gcc generates an executable named a.exe by default. (On UNIX-like systems, the default name, for historical reasons, is a.out.) Normally you'd specify a name using the -o option.

Apparently the generated a.exe file generates a false positive match in your antivirus software, so the file is automatically deleted shortly after it's created. I see you've already contacted the developers of Avast about this false positive.

Note that antivirus programs typically check the contents of a file, not its name, so generating the file with a name other than a.exe won't help. Making some changes to the program might change the contents of the executable enough to avoid the problem, though.

You might try compiling a simple "hello, world" program to see if the same thing happens.

Thanks to Chrono Kitsune for linking to this relevant Mingw-users discussion in a comment.

This is not relevant to your problem, but you should print a newline ('\n') at the end of your program's output. It probably doesn't matter much in your Windows environment, but in general a program's standard output should (almost) always have a newline character at the end of its last line.

x86 Windows Options (Using the GNU Compiler Collection (GCC)), These additional options are available for Microsoft Windows targets: -mconsole. This option specifies that a console application is to be generated,  On Windows, gcc generates an executable named a.exe by default. (On UNIX-like systems, the default name, for historical reasons, is a.out .) Normally you'd specify a name using the -o option.

There is no issue with your code it is just exiting properly.

You have to run it in the command line which will show you all the info.

start->run->cmd, then cd to your directory. then a.exe. If you don't want to do that you can add a sleep() before the return in main.

More over, in your code when you pass print(5) to your function it's not being used.

gcc on Windows: generated "a.exe" file vanishes, (Since ahoffer's deleted answer isn't quite correct, I'll post this, based on information in the comments.) On Windows, gcc generates an  The steps are: Install Cygwin, which gives us a Unix-like environment running on Windows. Install a set of Cygwin packages required for building GCC. From within Cygwin, download the GCC source code, build and install it. Test the new GCC compiler in C++14 mode using the -std=c++14 option.

Try to compile with gcc but without all standard libraries using a command like this:

gcc  -nostdlib -c  test.c -o test.o; gcc test.o -lgcc -o test.exe

One of the mingw libraries binary must generate a false positive, knowing which library would be useful.

How to Install the Latest GCC on Windows, The main downside is that it jumbles the output messages generated during the build process. If your CPU has even more hardware threads, you  In short: it's a free C and C++ compiler for Microsoft Windows. GCC(GNU Compiler Collection) is a free and open source compiler for C and C++ (and other languages like Objective-C, Fortran, D). MinGW-w64is a free and open source C library for targetting Windows 32-bit and 64-bit platforms.

I confirm is due to Antivirus. I did this test: compile helloworld.c at t=0; within 1 second tell McAfee not consider helloworld.exe a threat. >> the file is still there If I am too slow, the file will be deleted.

Mingw-w64, Mingw-w64 is an advancement of the original mingw.org project, created to support the GCC compiler on Windows systems. It has forked it in 2007 in order to  Download gcc-win64 for free. x64 build of GCC for Windows. x64 C/C++ compiler for Windows using: - gmp - mpfr - mpc - isl - cloog - mingw-w64 - gcc - seh You need at least core2 command set support to run this application.

You try:

gcc -o YOUR_PROGRAM.exe main.c

How do I install GCC compiler on Windows 10 (64 bit)?, I need to install gcc compiler from https://gcc.gnu.org/ to run C programs using command prompt. How do I Suppose you have created hello. Since you're using Windows with WinDbg you need the proprietary PDB files, which contain the debugging information for debugger tools that come from Microsoft. GCC will generate debugging information that can be used by the gdb debugger (well known in Linux) for example. gcc -g:

GCC Cross Compiler Setup in Windows, How to setup GCC cross compiler in Windows to generate Linux binaries. Basically, GCC is used to compile C/C++ code for Linux systems. gcc -c -mno-cygwin mydll.c gcc -shared -o mydll.dll mydll.o -Wl,--out-implib,libmylib.dll.a then to attach. gcc -o myexe.exe test.o mydll.dll EDIT: Forgot the most important piece, you need to make a mydll.h file to include your method definition so the compiler knows to reserve a spot for the linker to fill in later on. It's as simple as

Install GCC 9 on Windows, programs on your Windows machine and generate native Windows executables. Also, MSYS2 tends to offer the latest stable versions of GCC  A port of the GNU Compiler Collection (GCC), including C, C++, ADA and Fortran compilers; GNU Binutils for Windows (assembler, linker, archive manager) A command-line installer, with optional GUI front-end, (mingw-get) for MinGW and MSYS deployment on MS-Windows; A GUI first-time setup tool (mingw-get-setup), to get you up and running with

WinLibs, The combination of these results in a free C/C++ compiler for Windows. Even though GCC and MinGW-w64 can be used on other platforms (e.g. Linux) to generate 

Comments
  • Have you some antivirus installed? Try disabling it and let us know.
  • Moved it to my desktop and tried compiling it there, same result again
  • The third window is Sublime Text 3
  • OK, a terminological train wreck. gcc probably has nothing to do with this. Look at your system logs and antivirus logs.
  • Actually ahoffer's deleted answer isn't quite correct; it suggests that the file name a.exe is the problem. In fact virus scanners check the contents of files, not their names. (In this case, it's a false positive.)
  • While I was attempting to solve the solution, I changed the for loop to loop from 0 to 5 rather than 0, to amount. Also I am running it in the command line. And I can't run a.exe if it's not there.
  • I see I mis-read your question. It says a.exe is disappearing, not the terminal window. My apologies.
  • Ahh, that makes sense :)
  • I think you're onto something though, since I printed some text after calling the print(int) function, and it executes fine. Any ideas?
  • try adding -O0 flag and see if that does anything. GCC could be optimizing everything out for some ungodly reason.
  • I've faced the same problem and compiling my file this way helped. Any idea about how could I narrow down which library is causing a problem?
  • It is customary to provide commentary along with your "code".
  • I tried redFives suggestion and it didn't work. Also my antivirus would notify me if it were to quarantine a file.