help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading & Linking Error


From: Robert Heller
Subject: Re: Loading & Linking Error
Date: Mon, 17 Jan 2005 22:11:18 +0100

  Matthew Leung <ubccis@gmail.com>,
  In a message on Mon, 17 Jan 2005 12:04:50 -0800, wrote :

ML> Hi.  I keep getting this error in the ld phase of compilation.  What
ML> does undefined reference mean?

It means you are not linking in the special C++ libraries.

Although it is true that compiling C++ code with 'gcc' rather than 'g++'
does work and that that with the 'proper' -l options you can even link
C++ code with the gcc command, it is generally easier and simpler to
just use the g++ command, which takes care of all of that for you:

ML> 
ML> 
ML> make
ML> gcc -g -c Globals.cpp
    g++ -g -c Globals.cpp
ML> Globals.cpp:34:2: warning: no newline at end of file
ML> gcc -g -c TeamMaker.cpp
    g++ -g -c TeamMaker.cpp
ML> In file included from
ML> 
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/include/g++-v3/backward/strstream:51,
ML>                  from Team.h:6,
ML>                  from TeamMaker.h:7,
ML>                  from TeamMaker.cpp:1:
ML> 
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/include/g++-v3/backward/backward_warning.h:32:2:
ML> warning: #warning This file includes at least one deprecated or
ML> antiquated header. Please consider using one of the 32 headers found
ML> in section 17.4.1.2 of the C++ standard. Examples include substituting
ML> the <X> header for the <X.h> header for C++ includes, or <sstream>
ML> instead of the deprecated header <strstream.h>. To disable this
ML> warning use -Wno-deprecated.
ML> In file included from TeamMaker.h:7,
ML>                  from TeamMaker.cpp:1:
ML> Team.h: In member function `double Team::MinorityScore(const WeightInfo&) 
const
ML>    ':
ML> Team.h:137: warning: converting to `int' from `const double'
ML> TeamMaker.cpp:19:2: warning: no newline at end of file
ML> gcc -o TeamMaker Globals.o TeamMaker.o
    g++ -o TeamMaker Globals.o TeamMaker.o
ML> Globals.o(.text+0x34): In function `LoadFile(std::basic_string<char,
ML> std::char_traits<char>, std::allocator<char> >)':
ML> /root/Desktop/TeamMaker/Globals.cpp:5: undefined reference to
ML> `std::basic_string<char, std::char_traits<char>, std::allocator<char>
ML> >::c_str() const'
ML> Globals.o(.text+0x4e): In function `LoadFile(std::basic_string<char,
ML> std::char_traits<char>, std::allocator<char> >)':
ML> 
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/include/g++-v3/bits/basic_string.h:872:
ML> undefined reference to `std::basic_ifstream<char,
ML> std::char_traits<char> >::basic_ifstream(char const*,
ML> std::_Ios_Openmode)'
ML> Globals.o(.text+0x5c): In function `LoadFile(std::basic_string<char,
ML> std::char_traits<char>, std::allocator<char> >)':
ML> /root/Desktop/TeamMaker/Globals.cpp:8: undefined reference to
ML> `std::allocator<char>::allocator()'
ML> Globals.o(.text+0x7b):/root/Desktop/TeamMaker/Globals.cpp:8: undefined
ML> reference to `std::basic_string<char, std::char_traits<char>,
ML> std::allocator<char> >::basic_string(char const*, std::allocator<char>
ML> const&)'
ML> Globals.o(.text+0x97): In function `LoadFile(std::basic_string<char,
ML> std::char_traits<char>, std::allocator<char> >)':
ML> 
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/include/g++-v3/bits/basic_string.h:872:
ML> undefined reference to `std::allocator<char>::~allocator()'
ML> 

You basically need to fix your Makefile.

ML> 
ML>                                 

                                     \/
Robert Heller                        ||InterNet:   heller@cs.umass.edu
http://vis-www.cs.umass.edu/~heller  ||            heller@deepsoft.com
http://www.deepsoft.com              /\FidoNet:    1:321/153






                                                                

reply via email to

[Prev in Thread] Current Thread [Next in Thread]