【问题标题】:What is the command for starting the program right after compiling in the GNU GCC compiler? [closed]在 GNU GCC 编译器中编译后立即启动程序的命令是什么? [关闭]
【发布时间】:2018-10-26 20:37:54
【问题描述】:

我正在寻找要插入到 Makefile 中的命令,以便在编译后直接启动程序。我无法在 GNU GCC 网站上找到它。

【问题讨论】:

  • 没有。
  • 编译器不启动程序。外壳可以。

标签: gcc makefile


【解决方案1】:

您可以将all 子句添加到构建和运行程序的makefile 中,如下例所示:

all: build run

build: a.out

a.out: foo.c
    gcc foo.c -o a.out

run:
    ./a.out

【讨论】:

    【解决方案2】:

    您可以将命令添加到构建可执行文件的规则中(称为foo):

    foo: foo.c
        gcc whatever
        ./foo
    

    或者(更好)使其成为一个单独的规则,以便make foo 构建可执行文件,make run-foo 构建它(如果需要)然后运行它:

    foo: foo.c
        ...
    
    .PHONY: run-foo
    
    run-foo: foo
        ./$<
    

    【讨论】:

      猜你喜欢
      • 2015-05-24
      • 1970-01-01
      • 2012-04-15
      • 2015-09-23
      • 2021-05-17
      • 2015-06-14
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多