Ubuntu:如何链接二进制文件
我有一个 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是 Ubuntu 不知道在哪里寻找二进制 xyz。
您需要向 shell 配置文件添加路径(它将告诉您的 shell 在哪里查找 xyz 等程序),或者将 xyz 添加到已包含在路径中的目录。
例如,/usr/bin 是通常存储二进制文件的位置之一。但是,我并不完全确定安装新二进制文件的普遍接受的位置是什么(/usr/bin 通常可能保留用于系统二进制文件)。
Ubuntu 默认使用 bash shell。在您的主目录 (~) 中,您可以检查/编辑 .profile 文件,并编辑或查看哪些目录添加到您的 PATH 变量中。
The problem is that Ubuntu doesn't know where to look for binary xyz.
You need to either add a path to your shell profile (it'll tell your shell where to look for programs like xyz) or add xyz to a directory that's already included in your path.
For example, /usr/bin is one place where binaries are stored normally. However, I'm not entirely sure what the generally accepted place to install new binaries is (/usr/bin might be generally reserved for system binaries).
Ubuntu by default uses a bash shell. In your home directory (~), you can check/edit your .profile file and either edit or see what directories are added to your PATH variable.
Ubuntu 将 PATH 环境变量设置为包含
~/bin
。因此,使xyz
从任何地方可执行的最简单方法是将xyz
移动到~/bin
,或者创建从 ~/bin 到xyz
的目录:或者,您可以 将
/path/to/xyz/directory/
添加到您的 PATH 环境变量中。Ubuntu sets your PATH environment variable to include
~/bin
. So the easiest way to makexyz
executable from anywhere is movexyz
to~/bin
, or to make a symlink from ~/bin to thexyz
's directory:Or, you could add
/path/to/xyz/directory/
to your PATH environment variable.