[vox-tech] grokking g++ errors

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Thu Feb 2 10:21:52 PST 2006


Peter Jay Salzman wrote:
> 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?

I usually copy messes like this to an editor and indent them, which returns
some sanity to the picture when you just read off the top couple of levels
of the outline.

"In typemangled function Protoloan::initialize, there was an undefined
reference to a method 'split', templated with a back_insert_iterator,
which accepts two parameters, the first of which is a basic_string and
the second of which is a back_insert_iterator."

It would be nicer if I had a tool to do this visual parsing for me, but
I don't... the source is usually what I concentrate on.

You didn't ask for assistance in actually troubleshooting this problem, but
templates traditionally must be defined before they are instantiated in the
source.  It is possible that newer compilers can handle definition after
instantiation, but I don't know how they do it.

--------
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::vector<
             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
                   , std::char_traits<char>
                   , std::allocator<char>
                 >
             >
         >
     >
)



-- 
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------


More information about the vox-tech mailing list