程序编译后如何在linux中执行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15072753/
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
How to execute a program in linux after compiling it?
提问by yrazlik
I am compiling a C code in linux with the following command:
我正在使用以下命令在 linux 中编译 C 代码:
gcc -o myprogram myprogram.c
If I hadn't given a name to it, I could have simply written the command ./a.out
to execute it. But now, to execute the program I just write "myprogram" to the command line, but it says "command not found". What can I do to execute it?
如果我没有给它命名,我可以简单地编写命令./a.out
来执行它。但是现在,要执行该程序,我只需将“myprogram”写入命令行,但它显示“未找到命令”。我能做些什么来执行它?
采纳答案by Bruno
It's possible that the current directory (".
") isn't on your PATH
. (You can check this by typing echo $PATH
, this is a list of directories delimited with" :
". ".
" should be in the list if you want to run something in the current directory.)
当前目录 (" .
") 可能不在您的PATH
. (您可以通过键入来检查这一点echo $PATH
,这是一个以“ :
”分隔的目录.
列表。如果您想在当前目录中运行某些内容,“ ”应该在列表中。)
If the current directory isn't on your PATH
, you'll need to type ./myprogram
(or whatever the correct path is).
如果当前目录不在您的 中PATH
,您需要输入./myprogram
(或任何正确的路径)。
回答by yrazlik
./myprogram
should do the trick.
应该做的伎俩。
(But really... have you looked at the contents of the directory after compiling the program "without name"? Or do you think ./a.out
is a magic sequence Bash recognizes?)
(但真的……你有没有在编译“无名”程序后查看目录的内容?或者你认为./a.out
是Bash识别的魔术序列?)