【问题标题】:When I compile .c file it always creates .exe file with name 'a'当我编译 .c 文件时,它总是创建名为 'a' 的 .exe 文件
【发布时间】:2017-11-15 10:44:19
【问题描述】:

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

【问题讨论】:

    标签: c gcc


    【解决方案1】:

    只需告诉 GCC 你想要的输出名称。

    gcc hello.c -o hello
    

    【讨论】:

      【解决方案2】:

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

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

      您可以在一个命令中完成编译和链接

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

      【讨论】:

        【解决方案3】:

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

        $ 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

        【讨论】:

          猜你喜欢
          • 2015-08-06
          • 1970-01-01
          • 2012-08-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多