Ubuntu:如何链接二进制文件 [英] Ubuntu: How to link a binary
问题描述
我有一个C ++代码.我编译了它,现在有了二进制xyz.现在,每次需要执行二进制文件时,我都必须切换到相应的目录才能使用./xyz来执行它,但是如何在任何地方使用命令xyz来运行二进制文件.如何将此二进制文件链接到ubuntu中的命令.我目前使用Ubuntu 10.10
I have a C++ code. I compiled it and I now have the binary xyz. Now everytime I need to execute the binary, I had to switch to the corresponding directory to execute it using ./xyz But how do I run the binary using a command say xyz from anywhere. How do I link this binary to a command in ubuntu. I currently use Ubuntu 10.10
推荐答案
Ubuntu将PATH环境变量设置为包括~/bin
.因此,在任何地方使xyz
可执行文件的最简单方法是将xyz
移至~/bin
,或将符号链接从〜/bin移至xyz
的目录:
Ubuntu sets your PATH environment variable to include ~/bin
. So the easiest way to make xyz
executable from anywhere is move xyz
to ~/bin
, or to make a symlink from ~/bin to the xyz
's directory:
ln -s /path/to/xyz/directory/ ~/bin
Or, you could add /path/to/xyz/directory/
to your PATH environment variable.
这篇关于Ubuntu:如何链接二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!