This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: undefined reference to `x'


Alex Triffitt wrote:
Hi guys,
Cheers for all your help. I've tried adding "drawWindow.o" to the linker line but then I get a further similar error, which requires more and more *.o files to be added. Because I am working with software that does compile on other machines I'm guessing this isn't the problem, feel free to correct me

A lot of the followup ask me questions which I don't really understand. I have a reasonable understanding of c++ but when it comes to someone elses code that isn't documented I'm pretty lost! Someone asked how they are declared in the class, is that how they are declared in the header file? If so the yare just declared as public functions.

Someone else asked me if the object files were contained within one of the libraries. I think part of my lack of understanding of c++ is how libraries work. If anyone could point me in the direction of a good tutorial on libraries I might be able to fathum something out.

I don't have a reference at hand, but the short answer is that libraries are collections of object files. There are two types: archives (like libm.a) or shared (like libcairo.so). They are referenced on the command line by -l followed by the library name, without the "lib" or suffix: -lm or -lcairo. You can link with standard system libraries (in /usr/lib) or you can create your own. Many large programs will create private libraries as a part of an incremental build process, then link with them to create the final program.

When you link a program to create an executable,
you need to specify all of the object files which
contain referenced functions.  That includes your
drawWindow.o file.  You can either specify the
file on the command line, or specify a library
which contains the file.  The linker will search
libraries which you specify to find object files
which contain the functions referenced in previous
object files, for example drawWindow::~drawWindow().

The command line you give seems to reference only
system libraries, not private libraries.  One might
expect to see a reference to a private library
containing drawWindow.o (and all of the object files
it requires).  As Ingo suggested, perhaps something was
lost from the link line.


Thankyou for all your replies, that gave me some ideas and I've spent quite some time trying out what you have said. Any other help would be really appreciated
Alex





----------------------------------------
From: ikrabbe.ask@web.de
To: gcc-help@gcc.gnu.org
Subject: Re: undefined reference to `x'
Date: Wed, 2 Aug 2006 22:32:12 +0200
CC: alextriffitt@hotmail.com

Am Mittwoch, 2. August 2006 18:19 schrieb Alex Triffitt:
[...]

g++ -g -o iNSpect configFile.o eventBuilder.o vizNodeList.o vizNode.o
vizLine.o iNSpect.o vizProperties.o simWindow.o toolkitWindow.o
vizManager.o nodeStats.o -pthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0
-lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0
-lgmodule-2.0 -ldl -lgthread-2.0 -lglib-2.0   -Wl,--export-dynamic
-lgtkglext-x11-1.0 -lgdkglext-x11-1.0 -lGLU -lGL -lgtk-x11-2.0 -lpangox-1.0
-lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0
-lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0

I get the following error;

vizManager.o: In function
`~vizManager':/home/triff/inspect-triff-beta/src/vizManager.cpp:99:
undefined reference to `drawWindow::~drawWindow()'
[...]
Well, you should examine where the drawWindow class is or should be defined. Most usefully it would live in file like drawWindow.cpp which then should compile into drawWindow.o and should then be added to the linker line above.

What's about toolkitWindow.o ? Anyway as I assume from the layout of your errors, drawWindow is a locally defined object, which should live somewhere near your code. Or should it be in some library ?

You may just have forgotten object file or libary. Try to find out which.



--
Michael Eager	 eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]