gcc on Windows: generated “a.exe” file vanishes

前端 未结 8 2126
一个人的身影
一个人的身影 2021-01-12 12:01

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 

void print(int amount)         


        
相关标签:
8条回答
  • 2021-01-12 12:25

    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.

    0 讨论(0)
  • (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.

    0 讨论(0)
  • 2021-01-12 12:29

    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.

    0 讨论(0)
  • 2021-01-12 12:29

    a.exe is also the name of a virus. I suspect your computer's security software is deleting or quarantining the file because it believes it is a virus. Use redFIVE's suggestion to rename your output file to "print.exe" so that the virus scanner does not delete it.

    0 讨论(0)
  • 2021-01-12 12:31

    You try:

    gcc -o YOUR_PROGRAM.exe main.c
    
    0 讨论(0)
  • 2021-01-12 12:31

    If suppose you get the error near a.exe while running the file , Theen follow the below steps: 1.open virus & threat protection 2.there select manage settings in virus & threat protection settings 3.there is real time protection and cloud delivered protection is in ON then OFF the real time protection and cloud delivered protection.!

    (https://i.stack.imgur.com/mcIio.jpg)

    0 讨论(0)
提交回复
热议问题