简体   繁体   English

从makefile运行Executable

[英]Run Executable from makefile

Hey I just have a quick question about makefile's. 嘿,我只是有一个关于makefile的快速问题。 Is there some way to auto run the executable generated from a makefile? 有没有办法自动运行从makefile生成的可执行文件?

Like if I just type "make" it will compile and build and automatically execute so I can skip the extra step of ./myExecutable 就像我只输入“make”一样,它会编译并构建并自动执行,所以我可以跳过./myExecutable的额外步骤

I have down in my notes: 我记下来了:

run: prog1
        ./prog1

But it doesn't seem to work. 但它似乎没有用。

Thanks 谢谢

If you run make without specifying any targets, it would execute the first target it finds within the Makefile. 如果在没有指定任何目标的情况下运行make,它将执行它在Makefile中找到的第一个目标。 By convention all is the name of such a target. 按照惯例, all都是这样一个目标的名称。

If you make run a pre-requisite for all and mark both all and run as PHONY targets, you should be good to go. 如果您run一个先决条件, all和标记都allrun为伪目标,你要善于去。

all: run

run: prog1
    ./prog1

.PHONY: all run

BTW, I presume you already have some rules for building prog1 in your Makefile, and hence have not included it in the above shown Makefile. 顺便说一句,我认为你已经有了一些在Makefile中构建prog1规则,因此没有将它包含在上面显示的Makefile中。

An alternative would be to just invoke make explicitly with the run target, ie execute the following command: 另一种方法是只使用run目标显式调用make,即执行以下命令:

make run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM