LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Hello World linking Errors (https://www.linuxquestions.org/questions/programming-9/hello-world-linking-errors-427940/)

shotokan 03-24-2006 03:46 AM

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?

bulliver 03-24-2006 04:05 AM

gcc is a "C" compiler. Try "g++ HELLO.CPP".

Hko 03-24-2006 04:13 AM

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

jlliagre 03-24-2006 04:16 AM

and don't use uppercase in file names/extensions, that's ugly.

shotokan 03-24-2006 04:16 AM

Thank you very very much!


All times are GMT -5. The time now is 12:03 AM.