LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 03-24-2006, 04:46 AM   #1
shotokan
Member
 
Registered: Mar 2005
Distribution: slackware, LFS
Posts: 204

Rep: Reputation: 30
Hello World linking Errors


Hello I tying to to learn C++ I'm using the "SAM'S Teach Yourself C++ in 24 HOURS:THIRD EDITION" book. I have GCC-3.3.4.

I tried to compile the HELLO.CPP file:
Code:
#include <iostream>

int main()
{
        std::cout << "Hello World!/n";
        return 0;
}
But when I do:
Code:
gcc HELLO.CPP
I get:
Code:
/tmp/ccO9otYD.o(.text+0xd): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
/tmp/ccO9otYD.o(.text+0x60): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccO9otYD.o(.text+0x9f): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccO9otYD.o(.text+0xce): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccO9otYD.o(.text+0x127): In function `main':
: undefined reference to `std::cout'
/tmp/ccO9otYD.o(.text+0x12c): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccO9otYD.o(.text+0x155): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init()'
/tmp/ccO9otYD.o(.text+0x186): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccO9otYD.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
I don't understand any of this:

Anyone have a suggetion?
 
Old 03-24-2006, 05:05 AM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 77
gcc is a "C" compiler. Try "g++ HELLO.CPP".
 
Old 03-24-2006, 05:13 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Use a backslash instead:
Code:
int main()
{
        std::cout << "Hello World!\n";
        return 0;
}
Also, I'd recommend compiling with"
Code:
g++ -Wall -pedantic -o hello hello.cpp
This makes sure that:
  • The executable will have the name "hello" instead of "a.out".
  • You get all warnings about your code
 
Old 03-24-2006, 05:16 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
and don't use uppercase in file names/extensions, that's ugly.
 
Old 03-24-2006, 05:16 AM   #5
shotokan
Member
 
Registered: Mar 2005
Distribution: slackware, LFS
Posts: 204

Original Poster
Rep: Reputation: 30
Thank you very very much!
 
  


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
linking problems - 'undefined reference' errors back2morrie Programming 1 06-14-2005 09:02 AM
world writeable files will not stay world writeable antken Mandriva 1 03-02-2004 06:04 PM
Linking errors dhanakom Programming 4 07-08-2003 03:12 AM
Linking errors dhanakom Linux - Newbie 4 07-07-2003 06:34 PM
emerge errors during emerge -u world busbarn Linux - Distributions 6 04-23-2003 10:37 AM


All times are GMT -5. The time now is 03:58 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration