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 ...
- 04-17-2011 #1Just 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:
I compile with GCC: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; }
The file permissions are:Code:g++ sample.cpp -o sample
The file property "Allow executing file as program" is checked.Code:-rwxr-xr-x 1 jimmy jimmy 7719 2011-04-17 10:40 sample
Why does this file not run when I double click it from the GUI?
- 04-17-2011 #2Linux Guru
- 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!
- 04-17-2011 #3Just Joined!
- Join Date
- Jul 2006
- Location
- localhost
- Posts
- 22
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
- 04-28-2011 #4Just 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).


Reply With Quote
