LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 12-19-2004, 11:54 PM   #1
shams
Member
 
Registered: Jan 2004
Posts: 537

Rep: Reputation: 30
Question C++ code error


hi,
i downloaded the book on C++ "T1C2Vone.pdf" from http://www.planetpdf.com,and started to read,the book is so comprehensive,this is the first program in the book for C++:

// :co2:Hello.cpp
// Saying Hello with c++
#include <iostream>
using namespace std;

int main() {
cout << "Hello World! I am "
<< 8 << " Today! " << endl;
} ///:~
but this frist program failed to compile this is the output:
[root@localhost co2]# gcc -o Hello Hello.cpp
/tmp/ccNbJLzb.o(.text+0x14): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/ccNbJLzb.o(.text+0x2e): In function `main':
: undefined reference to `std::cout'
/tmp/ccNbJLzb.o(.text+0x33): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccNbJLzb.o(.text+0x3c): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >:perator<<(int)'
/tmp/ccNbJLzb.o(.text+0x45): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccNbJLzb.o(.text+0x4e): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccNbJLzb.o(.text+0x7a): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccNbJLzb.o(.text+0xa9): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccNbJLzb.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
plz help me.
 
Old 12-20-2004, 12:03 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Try g++ instead of gcc ...

Cheers,
Tink
 
Old 12-20-2004, 11:40 AM   #3
bm17
Member
 
Registered: Sep 2004
Location: Santa Cruz, CA, USA
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
Yes, you are not linking against the c++ library. You can use g++ on the command line, or you can also add "-lstdc++" to the end of the line.
 
  


Reply



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
C code 'gets' error boxerboy Programming 6 08-28-2005 03:27 PM
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM
LPRng error 'NONZERO RFC1179 ERROR CODE FROM SERVER' ivanscheers Linux - Networking 0 10-11-2004 02:50 AM
error with the code suchi_s Programming 2 09-30-2004 05:48 AM
Synaptic error: "sub-process /usr/bin/dpkg returned an error code (2)" firefly2442 Linux - Software 3 02-04-2004 06:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:55 AM.

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
Open Source Consulting | Domain Registration