我正在使用GCC版本4.7.1,但我也在GCC 4.8上尝试过此操作。这是我要编译的代码:
#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;
}
看起来应该能用,当我编译时...
gcc main.c
需要一段时间才能编译,产生一个a.exe
文件,该a.exe
文件消失。它不会给我任何代码错误。
这是一份证明,因为有些人误解了这一点:
(由于ahoffer删除的答案不太正确,因此我将根据评论中的信息发布该答案。)
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.
您可以尝试编译一个简单的“ hello,world”程序,看看是否发生了同样的事情。
感谢Chrono Kitsune在评论中链接到有关Mingw用户的讨论。
这与您的问题无关,但是您应该'\n'
在程序输出的末尾打印换行符()。在您的Windows环境中,这可能无关紧要,但通常,程序的标准输出(几乎)在最后一行的末尾始终应具有换行符。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句