制作 Ubuntu 可执行文件
我使用 gcc 编译器编写了一个 C 程序。现在它没有 GUI 组件。我正在使用 makefile 编译它并在终端中运行它。我需要部署它,以便可执行文件是独立的。我希望可执行文件有一个图标,单击时在终端中启动程序。谁能告诉我该怎么做?
i have made a program in C using the gcc compiler. Right now it has no GUI components. I am compiling it with makefile and running it in the terminal. I need to deploy it so that the executable is standalone. I want the executable to have an icon and when clicked start the program in the terminal. Can anyone tell me how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基础知识
(免责声明:以下内容是在 kubuntu 上进行测试的,您可能需要对您的系统进行一些调整)
实际上有一个标准可以做到这一点,不仅适用于 Ubuntu,而且适用于任何数量的 *nix 系统。请参阅:http://www.freedesktop.org/wiki/Howto_desktop_files:
假设您有您要部署的
foo.bin
文件。根据 文件系统层次结构标准,这是一个放置它的好地方(如果您不使用包manager) 是/usr/local/bin/
。您还需要一个图标,我假设您的艺术天赋产生了foo.png
,并且它的好地方可能是/usr/local/share/icons/
。现在您需要创建如下所示的
foo.desktop
:并将其放入
/usr/share/applications/
中。您也许可以使用菜单编辑器来创建这样的文件。在
~/.local/share/applications/
下查找生成的桌面文件。这应该可以解决问题。
另一个约定是将所有内容都放在
/opt/foo/
下,并创建到/usr/local/
的符号链接。跨 DE 与 Portland
Portland 项目 提供
xdg-*
命令行实用程序,可以轻松地以 DE(GNOME、KDE 等)独立方式安装应用程序的图标/菜单项/资源文件。请参阅 KDE 和linuxuser.co.uk 上的 GNOME 跨桌面开发教程。
更好的方法
对于部署,您应该考虑创建一个
*.deb
包。 (带有您的可执行文件、*.desktop
文件和图标)。关于这个主题有几个教程,例如 http://www.linuxfordevices.com/c/a/Linux-For-Devices-Articles/How-to-make-deb-packages/。请注意,如果您使用包管理器,文件位置的约定将变为
/usr/
而不是/usr/local/
。一路走下去
如果您愿意的话,下一步就是设置您自己的存储库,或者 PPA< /a>.
The basics
(disclaimer: the following was tested with kubuntu, you might need to make some adjustments for your system)
Actually there is a standard to do that, not just for Ubuntu but for any number of *nix systems. Consult: http://www.freedesktop.org/wiki/Howto_desktop_files:
Lets assume you have your
foo.bin
file you want to deploy. According to the Filesystem Hierarchy Standard, a good place to put it (if you are not using a package manager) is/usr/local/bin/
. You will also need an icon, I will assume your artistic talent producedfoo.png
, and a good place for it might be/usr/local/share/icons/
.Now you need to create
foo.desktop
that might look like this:and put it in
/usr/share/applications/
.You might be able to use your menu editor to create such a file. Look for the generated desktop file under
~/.local/share/applications/
.This should do the trick.
Another convention is to put everything under
/opt/foo/
and create symbolic links to/usr/local/
.Cross DE with Portland
The Portland project provides the
xdg-*
command line utilities that make it easy to install the application's icon / menu entry / resource file, in a DE (GNOME, KDE, etc) independent way.See the KDE & GNOME cross-desktop development tutorial on linuxuser.co.uk.
A better way
For deployment you should consider creating a
*.deb
package. (with your executable,*.desktop
file and icon). There are several tutorials on this subject e.g. http://www.linuxfordevices.com/c/a/Linux-For-Devices-Articles/How-to-make-deb-packages/.Note that if you are using a package manager, the convention for file location becomes
/usr/
instead of/usr/local/
.Go all the way
The next step, if you are inclined to take it, is setup your own repository, or PPA.
Chen的链接获取桌面图标和菜单条目;特别是对于 Ubuntu(以及大多数 Debian 衍生系统),有很多很好的文档。可以从以下链接开始使用: https://wiki.ubuntu.com/ Packaging?highlight=%28CategoryPackaging%24%29
从“PackagingGuide”开始阅读。 :)
至于在 X 下的终端中运行您的应用程序 - 在 Ubuntu 上 - 只需运行
x-terminal-emulator
命令由“update-alternatives”管理,并且将是指向任何首选的符号链接系统上有 xterm 模拟器。对于 Kubuntu 系统,它通常是 kterm,对于常规 Ubuntu 系统,它可能是 gnome-terminal 等。但是,如果安装了 X,您可以指望 x-terminal-emulator 可用。-e
选项适用于所有这些命令,因为它是一个 xterm 命令,它们都为了兼容性而实现了该命令。Chen's link gets the desktop icon and menu entry; for Ubuntu specifically (and really any Debian-derived system, for the most part), there is a whole lot of good documentation. It's available starting at this link: https://wiki.ubuntu.com/Packaging?highlight=%28CategoryPackaging%24%29
Start reading at "PackagingGuide". :)
As far as running your app in a terminal under X - on Ubuntu - just run
The
x-terminal-emulator
command is managed by "update-alternatives" and will be a symlink to whatever the preferred xterm emulator is on the system. For a Kubuntu system, it'll usually be kterm, for a regular Ubuntu system it'll likely be gnome-terminal, etc. But you can count on x-terminal-emulator being available if X is installed. And the-e
option works for all of them, because it's an xterm command which they all implement for compatibility.