简体   繁体   English

如何使用MakeFile运行不带“ ./”的可执行文件?

[英]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.

相关问题 如何在不在Cygwin上运行“ Startxwin”的情况下将“ myfile.exe”作为独立的可执行文件运行? - How can I run “myfile.exe” as a standalone executable file without running “Startxwin” on Cygwin? 从makefile运行Executable - Run Executable from makefile 使用makefile,LD_PRELOAD到可执行文件 - Using makefile, LD_PRELOAD to executable file 如何使用 `execl()` 在 C/C++ 中运行系统命令,将 function arguments 仅作为命令行而不是可执行文件传递? - How can I run system commands in C/C++ using `execl()`, passing the function arguments only as a command line, not as an executable file? 使用 linux 如何将文件的内容作为参数传递给可执行文件? - using linux how can I pass the contents of a file as a parameter to an executable? 使用 cgreen 从 makefile 运行可执行文件 - run executable from makefile with cgreen 使可执行文件在Linux中运行而无提示 - Make executable file run without prompt in linux 如何在可执行文件上运行脚本? - how to run script on executable file? 如何使用子进程在 Python 中运行带有文件输入/输出的可执行文件? - How to run executable with file input/output in Python using subprocess? 如何使用bash脚本在其他文件夹中运行可执行文件? - How can I run executable in a different folder with a bash script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM