LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-16-2006, 10:13 AM   #1
platipo
LQ Newbie
 
Registered: Dec 2006
Distribution: Kubuntu
Posts: 5

Rep: Reputation: 0
gcc question


Hi, I'm quite a newbie, and I have a problem with gcc: I tried to compile a simple hello world like program, I have inluded iostream, and the compiler seems to have no problem with that (if I put iostream.h it warns me that the header is deprecated/antiquated) but it tells me cout isn't defined... how can that happen? Any suggestions?
 
Old 12-16-2006, 10:14 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,371

Rep: Reputation: Disabled
You use g++ to compile C++ programs. If you're going to use gcc, then you need to link the C++ library, e.g. by using "gcc -lstdc++ hello.c".

Edit: do you also have "using namespace std;" or "using std::cout" in your program?
 
Old 12-16-2006, 10:22 AM   #3
platipo
LQ Newbie
 
Registered: Dec 2006
Distribution: Kubuntu
Posts: 5

Original Poster
Rep: Reputation: 0
already tried that; g++ gives me just the same problem, I have none of the lines you mentioned in my program, gonna try now

Edit: using namespace std gives me a load of errors and warnings, while using std::cout removes that error and leaves me with only endl undefined

Edit2:tried removing endl, it tells me of lots of undefined references to std::ios_base::init in function _static_inizialization_and_destruction_0
and of more undefined references to std::cout, to std::basic_ostream<char,and to _gxx_personality_v0

Last edited by platipo; 12-16-2006 at 10:35 AM.
 
Old 12-16-2006, 10:25 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,371

Rep: Reputation: Disabled
If you use the deprecated header, you should still get an executable file. The warning is just a warning, not an error.
 
Old 12-16-2006, 10:26 AM   #5
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 70
Can you post the code.
 
Old 12-16-2006, 10:38 AM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,371

Rep: Reputation: Disabled
Quote:
Originally Posted by platipo
already tried that; g++ gives me just the same problem, I have none of the lines you mentioned in my program, gonna try now

Edit: using namespace std gives me a load of errors and warnings, while using std::cout removes that error and leaves me with only endl undefined
Obviously you'd need to change endl to std::endl as well..

But yes, please post your code.
 
Old 12-16-2006, 10:44 AM   #7
platipo
LQ Newbie
 
Registered: Dec 2006
Distribution: Kubuntu
Posts: 5

Original Poster
Rep: Reputation: 0
sure:here it is

#include <iostream>


int main()
{

cout<<"hello world"<<endl;
return 0;
}

this was my original code. I tried using std::endl too, but it gives me the same errors
 
Old 12-16-2006, 11:09 AM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,371

Rep: Reputation: Disabled
If you put "using namespace std;" under the include directive, what kind of warnings and errors are you getting? It should work ok. What exactly is the command you're using to compile?
 
Old 12-16-2006, 11:28 AM   #9
platipo
LQ Newbie
 
Registered: Dec 2006
Distribution: Kubuntu
Posts: 5

Original Poster
Rep: Reputation: 0
I'm simply using gcc filename.cpp, the errors I get are just the same I get with writing using std::cout and using std::endl; it seems I do NOT have iostream in the usr/include folder... and that might just be the problem, still, I tried compiling the same code on another machine with those libraries and... it still doesn't work.
 
Old 12-16-2006, 11:34 AM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,371

Rep: Reputation: Disabled
If you're using gcc, you need to link the C++ library. Add a "-lstdc++" to your compile line, or does that not work either?

Not sure about Kubuntu, but under Slack, the header files are in /usr/include/c++/<version>.
 
Old 12-16-2006, 11:58 AM   #11
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 70
The code should be like
Code:
#include <iostream>
using namespace std;
int main()
{

    cout<<"hello world"<<endl;

    return 0;
}
To compile the program, you would do something like
Code:
$g++ -o hello hello.cpp
 
Old 12-16-2006, 01:20 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,627
Blog Entries: 10

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
Or, just to develop a good habit, (or at least bear it in mind):

Code:
#include <iostream>
int main()
{

    std::cout<<"hello world"<<std::endl;

    return 0;
}

Cheers,
Tink

Last edited by Tinkster; 12-16-2006 at 01:36 PM.
 
Old 12-16-2006, 01:34 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,627
Blog Entries: 10

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
And really, this should be in Programming; moving it along.


Cheers,
Tink
 
Old 12-16-2006, 02:05 PM   #14
platipo
LQ Newbie
 
Registered: Dec 2006
Distribution: Kubuntu
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Tinkster
And really, this should be in Programming; moving it along.


Cheers,
Tink
sorry... it sounded as such a newbie question...
EDIT
btw thanks again, I think I solved the problem.

Last edited by platipo; 12-20-2006 at 06:04 PM.
 
  


Reply

Tags
c++, deprecated, headers


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Yet, Another Kubuntu Boot Problem Freddy the Cat Linux - Desktop 3 08-15-2006 12:38 PM
Kubuntu 6.06 problem tidiman07 Ubuntu 10 08-07-2006 10:19 PM
Kubuntu log in problem impeteperry Ubuntu 0 07-15-2006 07:18 AM
Kubuntu 5.04 problem Aurra Sing Ubuntu 7 07-15-2005 01:21 AM
mounting problem on kubuntu oldforce Ubuntu 2 04-25-2005 06:53 PM


All times are GMT -5. The time now is 04:36 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration