execute gcc complied file in ubantu via double click

iam_ak

New Member
Joined
Feb 23, 2018
Messages
6
Reaction score
12
Credits
0
Hello all,

I just complied a dummy program which prints something on the terminal.

how do i go about this by double-clicking the executable and It should open up the terminal and run the program in it automatically.

The executable already has all the required permissions.
These are the commands which i have given so far
Code:
$ gcc helloc.c -o hello
$chmod 777 hello
$ ls
hello hello.c
sudo chmod 777 hello
If i use ./hello it executes the program,but if i go to the file location and double click it,it opens up in a text editor.
 


Edit: i was able to run the application from the desktop by creating a .desktop file.How ever i am facing a new problem now

I notice that when i right click and click on properties i see
Type: shared library(application/x-sharedlib)

But for some executables it shows:
Type: shared library(application/x-executable)

I am able to run the x-sharedlib file but not the x-executable from the .desktop file.
Any idea why?
 
The permissions 777 would mean that anybody would be able to read, write and execute the program.
It would make more sense to use 755 (rwxr-x-r-x) - that way unauthorised people would not be able to modify or remove your program.

As for actually executing your program from the desktop via a .desktop file:
If the program is a GUI-based program
i.e. It uses some kind of graphics/windowing based framework (opengl, QT, wxWidgets, GTK etc etc.)
You just need to set the exec line in the .desktop file to the path and name of the program.
e.g.
Code:
exec=/path/to/executable

And you will be able to click on the .desktop file and run your application.

But if the executable is a terminal based application, and the exec line is:
Code:
exec=/path/to/executable

Your program will run, but it will run invisibly, in the background.

A terminal based program is normally meant to be ran in a terminal. So in order to see your program running - you will need to set your .desktop file to open the executable in a terminal-emulator.

e.g.
Code:
exec=xterm -e '/path/to/executable'

Or if your program has no user interaction - you could do this:
Code:
exec=xterm -e '/path/to/executable;read -p "press any key to  continue..." -n1 -s'

This would prevent the terminal window from disappearing as soon as it has finished executing your program.

And if you want to use a different terminal emulator to run your program in - you should be able to swap xterm (in the above examples) with your preferred terminal. Most terminals that I know of accept the -e parameter (but the -e parameter should always be the last parameter passed).

But if your preferred terminal does not work - xterm definitely will. And AFAIK xterm is usually installed by default.

I hope that helps!
 
Thanks for the quick reply.

Currently these are my two executables
hello(type:shared library (application/x-sharedlib)) and
serialhello(type:executable (application/x-executable))

Code:
arun@arun-VirtualBox:~/Desktop/code/c$ ls -l
total 364
-rwxr-xr-x 1 arun arun   8336 Mar  8 14:41 hello
-rw-r--r-- 1 arun arun    113 Mar  8 13:07 hello.c
-rwxr-xr-x 1 arun arun 355344 Jul  4  2011 serialhello

And these are the respective .desktop files
Code:
arun@arun-VirtualBox:~/Desktop$ more serialexecute.desktop
[Desktop Entry]
Name=Serialhello
Type=Application
Exec=/home/arun/Desktop/code/c/serialhello
Terminal=true

arun@arun-VirtualBox:~/Desktop$ more execute.desktop
[Desktop Entry]
Name=HelloWorld
Type=Application
Exec=/home/arun/Desktop/code/c/hello
Terminal=true

Both the applications are opening when i do ./hello or ./serialhello
The execute.desktop is also working,but the serialexecute.desktop file simply dosn't do anything.

I tried using exec=xterm -e '/home/arun/Desktop/code/c/serialhello' but it doesn't seem to do anything.
 
Did you try the other version?:
Code:
exec=xterm -e '/path/to/executable;read -p "press any key to  continue..." -n1 -s'

It may be that a terminal is popping up, executing the program and then disappearing before you can see it!
 
no the programs waits for me to enter some input,so it cannot dissappear.I think it has to do somthing with the file type.
One is type:shared library (application/x-sharedlib) and the other is of type:executable (application/x-executable).I'm havig trouble with the x-executable only :(
 

Staff online

Members online


Latest posts

Top