[英]How can I run an executable file without the “./” using a MakeFile?
I want to run my program with an executable without the "./" 我想使用不带“ ./”的可执行文件运行程序
For example lets say I have the makefile: 例如,假设我有makefile:
all: RUN
RUN: main.o
gcc -0 RUN main.o
main.o: main.c
gcc -c main.c
So in order to run the program normally I would say in the terminal "make" then put "./RUN" to invoke the program. 因此,为了正常运行程序,我会在终端“ make”中说,然后放入“ ./RUN”以调用程序。
But I would just like to say in the terminal "make" then "RUN" to invoke the program. 但是我只想在终端中说“ make”然后“ RUN”来调用程序。
So to conclude I would just like to say >RUN instead of >./RUN inside the terminal. 因此,总结一下,我只想在终端内说> RUN而不是> ./ RUN。 Is there any command I can use to do this inside the Makefile?
我可以在Makefile中使用任何命令来执行此操作吗?
When I just put "RUN" in the terminal it just says command not found. 当我在终端中仅输入“ RUN”时,它表示未找到命令。
It is a matter of $PATH , which is imported by make
from your environment . 这是$ PATH的问题 ,它是由
make
从您的环境中导入的。
You might set it in your Makefile
, perhaps with 您可以在
Makefile
设置它,也许使用
export PATH=$(PATH):.
or 要么
export PATH:=$(shell echo $$PATH:.)
but I don't recommend doing that (it could be a security hole). 但我不建议您这样做 (这可能是一个安全漏洞)。
I recommend on the contrary using explicitly ./RUN
in your Makefile
, which is much more readable and less error-prone (what would happen if you got a RUN
program somewhere else in your PATH
?). 相反,我建议在
Makefile
显式地使用./RUN
,这更易读,而且更不易出错(如果在PATH
其他位置有RUN
程序,会发生什么情况?)。
BTW, you'll better read more about make
, run once make -p
to understand the builtin rules known to make
, and have 顺便说一句,您最好阅读有关
make
更多信息,运行一次make -p
来了解已知的make
内置规则,并拥有
CC= gcc
CFLAGS+= -Wall -g
(because you really want all warnings & debug info) (因为您确实想要所有警告和调试信息)
and simply 和简单地
main.o: main.c
(without recipes in that rule) in your Makefile
(在该规则中没有配方)在您的
Makefile
change your makefile to 将您的makefile更改为
all: RUN
RUN: main.o
gcc -o RUN main.o && ./RUN
main.o: main.c
gcc -c main.c
just put ./filename in your makefile 只需将./filename放在您的makefile中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.