LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-31-2009, 08:22 AM   #1
mickwaffle
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Rep: Reputation: 0
Compiling C++ in Linux.


Hello, i am using Ubunto and have made a sample c++ program in text editor, i have the g++ compiler already installed, so I type in this command in terminal: g++ test.cpp -o test which creates a file called 'test', however when i run it, it will not open, nothing happens when i double click it even though the program has a 'cin' to what for a response.
 
Old 08-31-2009, 09:05 AM   #2
headrift
Member
 
Registered: Sep 2005
Distribution: Gentoo, Sabayon, Puppy, Arch
Posts: 165

Rep: Reputation: 29
Running chmod +x test in Terminal should get it.
 
Old 08-31-2009, 09:10 AM   #3
mickwaffle
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
nope, still nothing happens.. just blank
 
Old 08-31-2009, 09:11 AM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
Hi,

Could you please run 'file test' from the directory 'test' is located in and post the output ? Also, it may actually be compiling fine but there could be a bug in the code, please post the code if it doesnt need too much sanitising

cheers
 
Old 08-31-2009, 09:35 AM   #5
mickwaffle
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
ok, here is the output i get :

a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
and here is the code i am using:


Code:
#include <iostream>

main()
{
    int short tester;
    std::cout << "Hello World!";
    std::cin >> tester;
    return 0;
}
thanks for your time
 
Old 08-31-2009, 09:41 AM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by mickwaffle View Post
std::cout << "Hello World!";
std::cin >> tester;
std::cout is buffered, so the output won't appear until a std::endl is sent.

Code:
    std::cout << "Hello World!" << std::endl;
    std::cin >> tester;
Quote:
Originally Posted by mickwaffle View Post
however when i run it, it will not open, nothing happens when i double click it even though the program has a 'cin' to what for a response.
Double clicking a program is usually not correct for a non GUI program. You usually should run it in a shell. But I'm not sure of that in this case.

The current directory is normally not in the path in Linux, so you usually need to type
./test
rather than just
test
in order to run the program in a shell.

Last edited by johnsfine; 08-31-2009 at 09:45 AM.
 
Old 08-31-2009, 09:44 AM   #7
Guitarist88
Member
 
Registered: Feb 2004
Location: Nz
Posts: 240

Rep: Reputation: 30
It compiled and ran for me with no problems. Just in case you don't know after you compile, you can run your program by typing ./a.out.

You may also want to change your main function to be int main.
 
Old 08-31-2009, 09:49 AM   #8
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
Hmmm .. compiles and runs fine on Fed 11, version 4.4.1

Are you running it from a terminal ?

Quote:
Sorry... slow response

Last edited by kbp; 08-31-2009 at 09:50 AM.
 
Old 08-31-2009, 09:51 AM   #9
mickwaffle
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
hmm.. i tried everything you guys said and thanks, but still when i run it from the terminal nothing happens, so i think i am going to install fedora instead, as it was just recently i installed ubunto
 
Old 08-31-2009, 09:55 AM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by mickwaffle View Post
hmm.. i tried everything you guys said and thanks, but still when i run it from the terminal nothing happens, so i think i am going to install fedora instead, as it was just recently i installed ubunto
Can you show the output after you try running the program please? It's hard to say what the problem is without that.
 
Old 08-31-2009, 09:58 AM   #11
mickwaffle
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
when i try and run it from the terminal, there is no output, it just does nothing...

usr@ubuntu:~/Desktop$ chmod +x ./tester
usr@ubuntu:~/Desktop$

Last edited by mickwaffle; 08-31-2009 at 10:03 AM.
 
Old 08-31-2009, 10:04 AM   #12
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by mickwaffle View Post
when i try and run it from the terminal, there is no output, it just does nothing...

usr@ubuntu:~/Desktop$ chmod +x ./tester
usr@ubuntu:~/Desktop$
You still need to run the program (i.e. "./tester", no quotes). chmod just sets permissions ("man chmod" for more info). When commands just return nothing, it's usually a good sign (as in the case of chmod).
 
Old 08-31-2009, 10:10 AM   #13
mickwaffle
LQ Newbie
 
Registered: Aug 2009
Posts: 8

Original Poster
Rep: Reputation: 0
genius! thanks alot, that works! how can i get it to automatically start a terminal when i double click it on the desktop?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
To make known to linux the usb hardware at compiling linux kernel for arm based sbc selmaguzel Linux - Embedded & Single-board computer 1 06-08-2008 05:02 PM
Various Compiling Errors (GCC compiling Openal, GUIlib, xmms-wma) gregorya Linux - Software 2 08-27-2004 06:03 AM
Compiling in ACPI support on Compaq 2135CA (system crashes while compiling) Dag Linux - Laptop and Netbook 20 07-30-2004 08:56 PM


All times are GMT -5. The time now is 08:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration