Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

execute gcc complied file in ubantu via double click

Discussion in 'General Linux' started by iam_ak, Mar 8, 2018.

  1. iam_ak

    iam_ak New Member

    Joined:
    Feb 23, 2018
    Messages:
    6
    Likes Received:
    8
    Hello all,

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


    (Log in to hide this advertisement)


    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.
     
    wizardfromoz likes this.
  2. iam_ak

    iam_ak New Member

    Joined:
    Feb 23, 2018
    Messages:
    6
    Likes Received:
    8
    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?
     
    wizardfromoz likes this.
  3. JasKinasis

    JasKinasis Well-Known Member

    Joined:
    Apr 25, 2017
    Messages:
    306
    Likes Received:
    586
    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!
     
    wizardfromoz and nuna like this.
  4. iam_ak

    iam_ak New Member

    Joined:
    Feb 23, 2018
    Messages:
    6
    Likes Received:
    8
    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:
    [email protected]:~/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:
    [email protected]:~/Desktop$ more serialexecute.desktop
    [Desktop Entry]
    Name=Serialhello
    Type=Application
    Exec=/home/arun/Desktop/code/c/serialhello
    Terminal=true
    
    [email protected]:~/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.
     
  5. JasKinasis

    JasKinasis Well-Known Member

    Joined:
    Apr 25, 2017
    Messages:
    306
    Likes Received:
    586
    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!
     
  6. iam_ak

    iam_ak New Member

    Joined:
    Feb 23, 2018
    Messages:
    6
    Likes Received:
    8
    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 :(
     

Share This Page