Gcc on Windows: the generated file "a.exe" disappears

I am using GCC version 4.7.1, but I 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 seems like it should work, and when I compile with ...

 gcc main.c 

It takes some time to compile, the a.exe file is a.exe , and the a.exe file disappears. This does not give me any errors with my code.

Here's the gif evidence, as some people misinterpret this: proof

+7
source share
6 answers

(Since ahoffer the deleted answer is not entirely correct, I will post it based on the information in the comments.)

On Windows, gcc by default creates an executable file called a.exe . (On UNIX-like systems, the default is a.out by default.) You usually specify a name with 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 its creation. I see that you have already contacted the Avast developers about this false positive.

Please note that antivirus programs usually check the contents of the file and not its name, therefore, generating a file with a name other than a.exe will not help. However, making some changes to the program may change the contents of the executable file to avoid the problem.

You can try creating 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 does not apply to your problem, but you should print a new line ( '\n' ) at the end of your program output. This probably doesn't matter much in your Windows environment, but in general, standard program output should (almost) always have a newline at the end of the last line.

+7
source

There is no problem with your code, it just exits correctly.

You should run it on the command line, which will show you all the information.

start-> run-> cmd, then cd to your directory. then a.exe. If you do not want to do this, you can add sleep () before returning to main.

Moreover, in your code, when you pass print(5) your function, it is not used.

+2
source

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

Antivirus next to compilation instructions

0
source

You are trying:

 gcc -o YOUR_PROGRAM.exe main.c 
-1
source

a.exe is also a virus name. I suspect that your computer security software deletes or quarantines the file because it considers it to be a virus. Use the redFIVE command to rename your output file to the file "print.exe" so that the antivirus does not delete it.

-2
source

You can stop the antivirus software from deleting your .exe by specifying the full path to the file (for example, c: \ MyProject) in the "paths to be excluded from scanning" section of the antivirus software.

-2
source

Source: https://habr.com/ru/post/971989/


All Articles