Subject: Re: errors
From: Matthew Cary (email@example.com)
Date: Sat May 18 2002 - 14:26:12 PDT
I've seen several questions similar to this below, so I'll make a comment
that hopefully will be helpful to the entire class.
My comments follow the message below.
> > I have written up my part of the code for the frequency assignment and
> > have been testing it. I tried to compile it and it spit out the usual
> > syntax errors and whatnot. After I fixed those a new error popped up.
> > This is what it says
> > fiji% make
> > g++ -o freq main.o
> > main.o: In function `std::allocator<char>::~allocator()':
> > /uns/encap/gcc-3.0.4/include/g++-v3/bits/stl_algobase.h(.text+0x218):
> > undefined
> > reference to `Tree::Tree(std::string)'
> > /uns/encap/gcc-3.0.4/include/g++-v3/bits/stl_algobase.h(.text+0x255):
> > undefined
> > reference to `Tree::Update(std::string)'
> > /uns/encap/gcc-3.0.4/include/g++-v3/bits/stl_algobase.h(.text+0x282):
> > undefined
> > reference to `Tree::Print(std::ostream&, int)'
> > collect2: ld returned 1 exit status
> > make: *** [freq] Error 1
> > I really don't know how to interpret this but it doesn't seem to like the
> > some of my methods. Can you tell me what is going on? I'll include my
> > files in case those will help.
Firstly, this student was wise to include his/her code. That makes it
a lot easier for us to help you.
You'll note that all the error messages occur in the file main.o. Note
that this is not your source-code file, but the object file. Hence these
error messages are occurring during linking, when your individual files
are stuck together to form a program.
The linker doesn't know anything about your source code. In fact, the
same linker is used to link object files built from C, C++, even fortran.
The only thing a linker knows about are functions and non-local variables
(i.e., all global and static variables). When some code makes a function
call, the linker figures out where that function lives, and fixes up the
The most common linker error is when the linker trys to resolve a function
or variable address, but can't find it. One cause for this is forgetting
to include all your object files in the OBJS variable definition in your
makefile. If you look back through the errors, you'll notice that several
of them refer to methods of a class called Tree---and indeed, this student
forget to add tree.o to definition of OBJS.
If you have made sure that all your files are getting used and you still
have errors, it probably means you've forgotten to define a function or
static variable that you use or have declared elsewhere. You'll have to
carefully read through the error messages to figure out your exact
problem; one of the disadvantages with modern C++ and the standard library
is that a single omission can cause a cascade of linker errors.
I hope this saves people some frustration. On the bright side, all
production-quality development tools can have cluttered error messages
like these. The skills you learn in getting code to build are extremely
This archive was generated by hypermail 2b25 : Sat May 18 2002 - 14:26:20 PDT