Linker broken?

Discussion in 'Mac Programming' started by kperryua, Sep 1, 2005.

  1. kperryua macrumors newbie

    Joined:
    Sep 1, 2005
    #1
    I'm trying to compile a very simple C++ program on the command line using gcc. It successfully creates the object files and all that, but the linker spits these errors out at me:

    Code:
    /usr/bin/ld: Undefined symbols:
    std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
    std::ios_base::Init::Init()
    std::ios_base::Init::~Init()
    std::cout
    std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
    std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
    ___gxx_personality_v0
    collect2: ld returned 1 exit status
    This suggests to me that the linker for some reason can't find the C++ standard libraries. What's up with that? I swear it was working a week ago...

    I installed Fink recently... might that have anything to do with it?

    Anyone know a fix?
     
  2. WebMongol macrumors member

    Joined:
    Sep 19, 2004
    Location:
    Bay Area, CA
    #2
    g++

    Use C++ compiler (g++ or c++) to compile and link C++ program.
     
  3. ChrisBrightwell macrumors 68020

    ChrisBrightwell

    Joined:
    Apr 5, 2004
    Location:
    Huntsville, AL
    #3
    g++ is just a symlink to gcc.

    kperryua, can you build HelloWorld.cpp?
     
  4. WebMongol macrumors member

    Joined:
    Sep 19, 2004
    Location:
    Bay Area, CA
    #4
    Even if g++ and gcc are sym links to the same program (actually it's not true for Mac OS X 10.3.9) they behave differently depending which name was used for invocation.
    g++ by default calls linker (ld) and specify C++ std library(-lstdc++).

    One can do this explicitly by building C++ program with extra parameter: -lstdc++. So to compile C++ hello.cc one can use
    g++ hello.cc -o hello1
    OR
    gcc hello.cc -lstdc++ -o hello2
     

Share This Page