GCC, C++, and broken linking

Kurt Granroth plug-discuss@lists.plug.phoenix.az.us
Wed, 8 Jan 2003 22:51:06 -0700


On Wednesday 08 January 2003 08:30 pm, Codie William Masters wrote:
> Somebody please explain what I'm doing wrong here. I'm trying to work on
> some of my Advanced Placement computer science AB projects here at home.
> Well, I typed in the code, checked it twice and ran 'gcc main.cpp' to no
> avail. First it gave me warnings about textspace standard so I fixed the
> code to make it recent (the book is 1994) and tried again. I now get all
> kinds of linker errors:
>
> /tmp/ccv7OZu3.o: In function `main':
> /tmp/ccv7OZu3.o(.text+0x36): 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>
> >&)'
>
> Does anyone know what I can do about this?

Yes.  All of those symbols are part of the standard C++ library.. none of 
those exist in the standard C library.  When you invoke the gnu compiler 
suite using 'gcc', it assumes (regardless of what you call your file) that 
the file is a C file.  Since it is C++, you'll need to invoke it with 'g++'

So this will work:

g++ main.cpp
-- 
Kurt Granroth - "KDE -- Conquer Your Desktop"
KDE Developer/Evangelist | granroth@kde.org
http://www.granroth.org  | kurt@granroth.org