C++ Learning Community Forum
September 11, 2010, 12:54:35 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Compiling problem  (Read 1189 times)
Juggernaut
N00b!!1
*
Posts: 3

Juggernaut


View Profile
« on: August 06, 2007, 12:06:51 AM »

I'm using g++.
I'm on Ubuntu Feisty Fawn.
(This happens on the Desktop.)


I made a basic c file that prints Hello World. I compiled it using

cd Desktop
THEN
g++ HelloWorld.c -o Program

Of course, HelloWorld.c is the source and Program is the outcome. It made an executable called "Program", but it won't run. I double clicked it and then tried it through Run.

 It worked when I ran it in the terminal like this:

user@place: /home/main/Desktop/Program
Hello World.user@place:

That's exactly how it was in the terminal.

How can I make it run, but not like that?
Logged
ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1241



View Profile
« Reply #1 on: August 06, 2007, 03:12:02 AM »

This sounds like more of an issue with desktop configurations than compiling. Im guessing your used to the windows environment where console windows are created for you. Im not entirely sure how to automatically create a console in linux when a program is clicked to run, but you could try setting up gnome (which is what im assuming your using since your using ubuntu) to open your program with say, xterm. If anyone knows the *right* way to do this, i would like to know as well (though i prefer KDE)
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
draco
Geek
*****
Posts: 137


View Profile
« Reply #2 on: August 06, 2007, 04:14:02 AM »

If I remember correctly, right click the icon and click something like Launcher Settings and check the tick box "Run in terminal."
Logged
Juggernaut
N00b!!1
*
Posts: 3

Juggernaut


View Profile
« Reply #3 on: August 06, 2007, 04:33:56 AM »

Yes, I'm used to Windows. I have gnome, and I don't see anything about launcher settings when I right click it. Isn't xterm for OS X? I'm using the Ubuntu distrobution of Linux, as I have stated.
Logged
CannonFodder
N00b!!1
*
Posts: 14


View Profile
« Reply #4 on: August 06, 2007, 06:46:36 AM »

That's exactly what should happen as far as I can tell.  Based on the terminal view everything is working great.  Since cout is the ostream for the terminal the program is called in, if you try to run it through the gui it does something like /[some dir]/Program; exit in a new terminal so the terminal closes as soon as the Program has stopped.  If you wanted Hello World to show up in a window (not a term) you'd need a little x11 coding, or if you wanted the terminal to remain open you would have to make the program wait for something, so it did not stop after printing the string.

PS cout does NOT put a \n on its outs so if you want a new line you have to put it in there yourself.
Logged

If only the world's problems were this easy to solve:
Code:
[God@earth ~]$ ps aux | grep Devil | awk '{print $2}' | xargs kill -9
"The primary purpose of the DATA statement is to give names to constants; instead of
referring to pi as 3.141592653589793 at every appearance, the variable PI can be given
that value with a DATA statement and used instead of the longer form of the constant.
This also simplifies modifying the program, should the value of pi change."
- FORTRAN manual for Xerox computers
Juggernaut
N00b!!1
*
Posts: 3

Juggernaut


View Profile
« Reply #5 on: August 06, 2007, 10:53:07 PM »

Well if that's happening right, what about those huge programs like games? By the way, I used printf, not cout, this is a C file.
Logged
ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1241



View Profile
« Reply #6 on: August 07, 2007, 01:54:49 AM »

Quote
Isn't xterm for OS X?
Could be, though its most likely on anything with X, as its the standard terminal emulator for X http://en.wikipedia.org/wiki/Xterm
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
Keira
semi-N00b
**
Posts: 32


BFF !!


View Profile
« Reply #7 on: August 14, 2007, 12:23:04 PM »

Yes you have to tell it to run in terminal.  Right click and choose custom command and type "xterm". 
Also make sure you have execution permissions (chmod +x).
Also add getchar() after the printf() function to make it wait for user input so it doesn't run and exit so fast that you don't see the terminal pop up. 

Also g++ is the c++ compiler.  Use gcc to compile C programs.
« Last Edit: August 14, 2007, 12:36:18 PM by Keira » Logged

"All is fair in love and war."
mleveill
1337 L0LCoder
C++ Freak
***
Posts: 430


IM IN UR PROGRAMZ WRITIN UR CODEZ!


View Profile
« Reply #8 on: August 14, 2007, 12:51:53 PM »

Quote
By the way, I used printf, not cout
will do the same thing (in this case anyways)
Logged

Quote from: kohlrak
Common interests aren't always the best thing. Especially programming wise.
I could just picture a couple fighting over weather to "xor eax by eax" or "and eax by 0"...
Then kids'll come home and argue with their parents that readabilty is better than size and that "mov eax, 0" would be best because that's "more readable." (Even if it really isn't...)

LOLCode - http://lolcode.com/home
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!