views:

360

answers:

2

i have made a program in C using the gcc compiler. Right now it has no GUI components. So, I am basically compiling it with makefile and running it in the terminal. I need to deploy it so that the executable is standalone. So, basically 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?

+8  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 produced foo.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:

[Desktop Entry]
Comment=My awesome fooish application 
Exec=/usr/local/bin/foo.bin
Icon=/usr/local/share/icons/foo.png
Name=Foobar
NoDisplay=false
StartupNotify=false
Terminal=1
TerminalOptions=
Type=Application

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 Levy
thanx for this link, i will do the whole -deb package in the future but for my urgent needs I just want it to open up the executable in the terminal by clicking the icon. there are no GUI components in my code. how can this be done?
sfactor
@sfactor, the "Terminal=1" option Chen included in the `foo.desktop` file should cause the program to open in a terminal.
Nick Meyer
+1 for the PPA plug.
jldupont
+5  A: 

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

x-terminal-emulator -e /path/to/your/command

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.

dannysauer