Linux 从 makefile 运行可执行文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15566405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run Executable from makefile
提问by ModdedLife
Hey I just have a quick question about makefile's. 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
谢谢
采纳答案by Tuxdude
If you run make without specifying any targets, it would execute the first target it finds within the Makefile. By convention all
is the name of such a target.
如果在没有指定任何目标的情况下运行 make,它将执行它在 Makefile 中找到的第一个目标。按照惯例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
和标志都all
和run
为伪目标,你要善于去。
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.
顺便说一句,我假设您已经prog1
在 Makefile 中制定了一些构建规则,因此没有将其包含在上面显示的 Makefile 中。
An alternative would be to just invoke make explicitly with the run
target, i.e. execute the following command:
另一种方法是使用run
目标显式调用 make ,即执行以下命令:
make run