[vox-tech] grokking g++ errors

Peter Jay Salzman p at dirac.org
Thu Feb 2 08:48:43 PST 2006


I've always had a hard time parsing g++'s verbose error messages.  For
example, this code (in ProtoLoan.cc):



// We've been passed a line of a csv file.  We'll parse that line and place
// it in a vector so we can populate the protoloan.
//
void ProtoLoan::initialize( const string &str )
{
   vector<string> fields;
   split( str, back_inserter(fields) );
}


// Takes a string and a container.  Splits the string based on comma
// separated fields and places each element into the container.  The
// container is defined as a template, so we can use vectors, lists, etc.
//
template <class Out> void split( const string &str, Out os )
{
   typedef string::const_iterator iter;

   iter i = str.begin();
   while ( i != str.end() )
   {
      i = find_if( i, str.end(), not_comma );

      // Find end of next word
      iter j = find_if( i, str.end(), is_comma );

      // Copy characters in [i, j)
      if ( i != str.end() )
         *os++ = string(i,j);
      
      i = j;
   }
}


Produces this error message:

$ make
g++  -W -Wall -g3  -c -o rmbs.o rmbs.cc
g++  -W -Wall -g3  -c -o protoloan.o protoloan.cc
g++  rmbs.o protoloan.o -o rmbs
protoloan.o: In function `_ZN9ProtoLoan10initializeERKSs':
/cygdrive/c/Documents and Settings/psalzman/home/RMBS/code/C++/protoloan.cc:19:
undefined reference to `void ProtoLoan::split<std::back_insert_iterator<std::vec
tor<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std:
:allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char>
> > > > >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >
 const&, std::back_insert_iterator<std::vector<std::basic_string<char, std::char
_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, st
d::char_traits<char>, std::allocator<char> > > > >)'
collect2: ld returned 1 exit status
make: *** [rmbs] Error 1



My mind reels trying to parse this.  I understand that split() isn't being
found by the linker, for some reason, but the rest of the message isn't too
helpful.

Is there a way to glean more information from the error message other than
the fact that the function isn't being found?

Thanks!
Pete


More information about the vox-tech mailing list