从makefile运行可执行文件 [英] Run Executable from makefile
问题描述
嘿,我只是有一个关于makefile的快速问题。是否有某种方法来自动运行从makefile生成的可执行文件?
像我只是键入make它会编译和构建并自动执行所以我可以跳过额外步骤./myExecutable
我在我的笔记中有:
run:prog1
./prog1
但它似乎无效。
感谢
如果您在不指定任何目标的情况下运行make,它会执行它在Makefile中找到的第一个目标。
如果你使运行 / code>
all
的先决条件,并标记 all
和
作为PHONY的目标,你应该很好去。
all:run
run:prog1
./prog1
.PHONY:all run
BTW,我想你已经有一些规则在你的Makefile中构建 prog1
,因此没有包含在上面显示的Makefile中。
另一种方法是使用 run
目标调用make,即执行以下命令:
运行
Hey I just have a quick question about makefile's. Is there some way to auto run the executable generated from a makefile?
Like if I just type "make" it will compile and build and automatically execute so I can skip the extra step of ./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. By convention all
is the name of such a target.
If you make run
a pre-requisite for all
and mark both all
and run
as PHONY targets, you should be good to go.
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.
An alternative would be to just invoke make explicitly with the run
target, i.e. execute the following command:
make run
这篇关于从makefile运行可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!