undefined reference to `x'

Michael Eager eager@eagercon.com
Wed Aug 2 17:53:00 GMT 2006


Alex Triffitt wrote:
> I am trying to compiled a rather complicated program. And I am constantly getting the error:
> "undefined reference to `<x>'" where x is a function in a class. For example I have the file vizManager.cpp which has at the very top the statment #include "drawWindow.h". Within vizManager.cpp there is a call to create a drawWindow object through the line "drawWindow(this)". The vizManager.cpp file compiles perfectly fine but when it comes to linking with the line:
> 
> 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()'
> :/home/triff/inspect-triff-beta/src/vizManager.cpp:99: undefined reference to `drawWindow::~drawWindow()'
> vizManager.o: In function `vizManager':/home/triff/inspect-triff-beta/src/vizManager.cpp:51: undefined reference to `drawWindow::drawWindow(vizManager*)'
> :/home/triff/inspect-triff-beta/src/vizManager.cpp:84: undefined reference to `drawWindow::~drawWindow()'
> :/home/triff/inspect-triff-beta/src/vizManager.cpp:51: undefined reference to `drawWindow::drawWindow(vizManager*)'
> :/home/triff/inspect-triff-beta/src/vizManager.cpp:84: undefined reference to `drawWindow::~drawWindow()'
> 
> The only way I have found around this is by adding the following lines near the top of vizManager.cpp:
> 
> drawWindow::drawWindow(vizManager*)
> {
> }
> drawWindow::~drawWindow()
> {
> }
> 
> This I don't think actually fixes the problem because then these functions are called do nothing and therefore cause a lot of errors.
> 
> Does anyone know what is going wrong? Is this a linking problem? Or a library problem? or something totally different. I suspect this is something to do with the fact I am trying to compile using GCC version 4.1.0 when the program was orginally written for an earlier version.

How are the constructors and destructor for the drawWindow class
declared and defined?

My guess is that you only have these declared in the class,
without providing bodies for the member functions.



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



More information about the Gcc-help mailing list