Find the answer to your Linux question:
Results 1 to 4 of 4
I am new to Linux. I am running Ubuntu 10.10. I have written C++ programs on Windows. I am now learning Linux to ensure my software is portable. I can ...
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    2

    Cannot run C++ executable file from Ubuntu GUI

    I am new to Linux. I am running Ubuntu 10.10.

    I have written C++ programs on Windows. I am now learning Linux to ensure my software is portable. I can compile and run C++ programs from the bash shell, but I cannot run my executable programs from the GUI.

    Here is my sample program:

    Code:
    #include <iostream>
    
    int main()
    {
        std::cout << "\n Enter number: ";
        int number = 0;
        std::cin >> number;
        std::cout << "\n Your number: " << number << "\n";
        return 0;
    }
    I compile with GCC:

    Code:
    g++ sample.cpp -o sample
    The file permissions are:

    Code:
    -rwxr-xr-x 1 jimmy jimmy 7719 2011-04-17 10:40 sample
    The file property "Allow executing file as program" is checked.

    Why does this file not run when I double click it from the GUI?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    This is not a GUI program. It has to run inside a text shell such as bash. Open a console/terminal window on the GUI, and then run the program. If you want it to output a GUI window to display the output, then you need to use the appropriate API's to do so. For cross-platform compatibility, try Qt.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jul 2006
    Location
    localhost
    Posts
    22
    Quote Originally Posted by LaserGuided View Post
    Why does this file not run when I double click it from the GUI?
    Welcome to linuxforums.org , LaserGuided!


    The program does run, but unlike in windows it doesn't spawn a command prompt to display the output.

    Most of the time when you run an executable from the GUI you only want the GUI portion to be displayed while the status messages printed to stdout remains hidden.

    You can explicitly run your program in a command prompt by either:
    1. choosing "Run in Terminal" from the file explorer if you use the default Gnome desktop
    2. create a launcher to your executable from the desktop right-click menu and change the command from "/home/jimmy/sample" to "xterm -hold -e /home/jimmy/sample" which will spawn a command prompt using xterm to display the output of your command.


    Hope this helps and good luck with your programs!
    / Djhg2000

  4. #4
    Just Joined!
    Join Date
    Apr 2011
    Posts
    2
    Thanks for your replies. This forum really helps the learning curve.
    My linux and windows machines are identical, but I'm doing most of my programming on the linux box now because g++ compiles significantly faster on linux.

    btw - I do use Qt (love it).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...