Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

windows

gcc

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: proof

like image 425
chapman Avatar asked Jul 09 '14 18:07

chapman


People also ask

Why are exe files missing?

Reasons for EXE Files Loss The most apparent reason for the issue “lost EXE file” is antivirus settings or virus or malware infection. Most of the viruses or malware are delivered through executable files, and the antivirus programs always make most of the executable files suspicious and block or even delete them.

How do I fix a missing EXE file?

The first and easiest method to fix a missing executable is to verify the integrity of the game files. Open your Steam Library, right-click the affected game and go to Properties > Local Files Tab. From there, hit 'Verify The Integrity Of Game Files', the process shouldn't take that long to complete.

Does compiler produce EXE file?

The compiler (or more specifically, the linker) creates the executable. The format of the file generally vary depending on the operating system.

Does gcc work on Windows?

GCC is portable and run in many operating platforms. GCC (and GNU Toolchain) is currently available on all Unixes. They are also ported to Windows (by Cygwin, MinGW and MinGW-W64). GCC is also a cross-compiler, for producing executables on different platform.


2 Answers

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

like image 170
Keith Thompson Avatar answered Oct 23 '22 10:10

Keith Thompson


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.

like image 4
JFR Avatar answered Oct 23 '22 11:10

JFR