当我编译.c文件时,它总是创建名为'a'的.exe文件

时间:2017-11-15 10:44:20

标签: c gcc

我使用GCC编译器在CMD上编译和运行C程序。 当我使用命令u'\xd0\xbf' to u'\u043f' 编译C程序时,它会创建一个名为gcc hello.c的可执行文件文件,但是当我使用IDE时,它使用与.c文件相同的名称a.exe。 是否可以在CMD上创建与.c文件相同的.exe文件名?

3 个答案:

答案 0 :(得分:4)

告诉GCC您想要的输出名称。

gcc hello.c -o hello

答案 1 :(得分:1)

您必须指定可执行文件的名称

gcc -c hello.c // compiling

gcc -o hello hello.o // linking
         ^------------------------- name of the executable

你可以在一个命令中进行编译和链接

gcc -o hello hello.c
         ^------------------------- name of the executable

答案 2 :(得分:0)

您需要了解输出的语法。以下是命令的描述:

$ gcc [options] [source files] [object files] -o output file

在您的情况下,您应执行以下命令:

$ gcc myfile.c -o myfile
$ ./myfile

有关更多说明和更优化的方法,请参阅以下网址: http://www.rapidtables.com/code/linux/gcc/gcc-o.htm