Thread: C++ undefined reference - Hello World

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    19

    C++ undefined reference - Hello World

    I am quite new to programming and even newer to linux (does that make sense?). A while back I started to program in C++ and found it quite easy on linux. I just used the command

    gcc hello.cpp -o hello

    And all was well. Now when I try and compile anything I get lots of strange errors. I tried to compile this program....

    Code:
    #include <iostream>
    
    int main()
    {
    	std::cout << "Hello world.";
    	return 0;
    }
    And got these errors...

    Code:
    gcc hello2.cpp -o hello2
    /tmp/ccfO003J.o: In function `main':hello2.cpp:(.text+0x27): undefined reference to `std::cout'
    :hello2.cpp:(.text+0x2c): 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/ccfO003J.o: In function `__tcf_0':hello2.cpp:(.text+0x46): undefined reference to `std::ios_base::Init::~Init()'
    /tmp/ccfO003J.o: In function `__static_initialization_and_destruction_0(int, int)':hello2.cpp:(.text+0x6f): undefined reference to `std::ios_base::Init::Init()'
    /tmp/ccfO003J.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
    collect2: ld returned 1 exit status
    Is there something wrong with my machine or my code?

    Any help appreciated

    Thanks

    Ironfistchamp

  2. #2
    Registered User
    Join Date
    Jan 2006
    Posts
    63
    Try using g++ which is the C++ compiler. gcc is the C compiler.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    19
    Yup that works. Boy do I feel stupid.

    Thanks

    Ironfistchamp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Gnarly Linking Error HELP!!!!
    By brooksbp in forum C++ Programming
    Replies: 8
    Last Post: 05-04-2007, 01:00 AM
  3. MinGW Linking GUI Program
    By Tonto in forum Tech Board
    Replies: 19
    Last Post: 08-23-2006, 03:28 PM
  4. How to: Use OpenGL with Jgrasp
    By Pickels in forum Game Programming
    Replies: 3
    Last Post: 08-30-2005, 10:37 AM
  5. nehe opengl prob
    By bluehead in forum C++ Programming
    Replies: 6
    Last Post: 03-29-2005, 12:01 AM