PDA

View Full Version : Strange compile error in subclass



space_otter
27th February 2010, 21:08
Hi, I'm using eclipse integration 1.6.1 and Qt 1.6.2. I'm having a problem creating a simple non-Qt class structure. I've created a folder called "math" and I have these files in it:

DElement.h


/**
* DElement.h
*
* Created on: Feb 27, 2010
* Author: Eric
*
* A generic abstract class for an "element" which can be used in a stack. So it can be a number or an equation.
* Subclasses need to be able to supply a string representation and be able to parse from a string.
*/

#ifndef DELEMENT_H_
#define DELEMENT_H_
#include <QtCore/QString>

class DElement {
public:
virtual QString toString() = 0;
virtual void fromString(const QString &string) = 0;

DElement();
virtual ~DElement();
};

#endif /* DELEMENT_H_ */


DElement.cpp

/*
* DElement.cpp
*
* Created on: Feb 27, 2010
* Author: Eric
*/

#include "DElement.h"

DElement::DElement() {
// Not much to do here
}

DElement::~DElement() {
// TODO Auto-generated destructor stub
}


DNumber.h

/**
* DNumber.h
*
* Created on: Feb 27, 2010
* Author: Eric
*
* DNumber represents a MAPM object which is also a DElement for display purposes.
*/

#ifndef DNUMBER_H_
#define DNUMBER_H_

#include "DElement.h"
// uses MAPM :)
#include <F:/Programs/mapm/M_APM.H>
#include <QtCore/QString>

class DNumber: public DElement, public MAPM {
public:
DNumber(double val);
virtual ~DNumber();
private:

};

#endif /* DNUMBER_H_ */


DNumber.cpp

/*
* DNumber.cpp
*
* Created on: Feb 27, 2010
* Author: Eric
*/

#include "DNumber.h"

DNumber::DNumber(double val) {
// TODO Auto-generated constructor stub
}

DNumber::~DNumber() {
// TODO Auto-generated destructor stub
}


And the following error is produced:

mingw32-make debug
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `G:/Documents/Projects/Demurr'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"f:\Programs\Qt4.6\qt\include\QtCore" -I"f:\Programs\Qt4.6\qt\include\QtGui" -I"f:\Programs\Qt4.6\qt\include\QtOpenGL" -I"f:\Programs\Qt4.6\qt\include" -I"f:\Programs\Qt4.6\qt\include\ActiveQt" -I"debug" -I"." -I"f:\Programs\Qt4.6\qt\mkspecs\win32-g++" -o debug\DNumber.o math\DNumber.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\Demurr.exe debug/DNumber.o debug/main.o debug/mainwindow.o debug/stacktabwidget.o debug/tabpage.o debug/stacktablemodel.o debug/moc_mainwindow.o debug/moc_stacktabwidget.o debug/moc_tabpage.o -L"f:\Programs\Qt4.6\qt\lib" -lopengl32 -lglu32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtOpenGLd4 -lQtGuid4 -lQtCored4
debug/DNumber.o: In function `DNumber':
G:\Documents\Projects\Demurr/math/DNumber.cpp:10: undefined reference to `DElement::DElement()'
G:\Documents\Projects\Demurr/math/DNumber.cpp:13: undefined reference to `DElement::~DElement()'
G:\Documents\Projects\Demurr/math/DNumber.cpp:10: undefined reference to `DElement::DElement()'
G:\Documents\Projects\Demurr/math/DNumber.cpp:13: undefined reference to `DElement::~DElement()'
debug/DNumber.o: In function `~DNumber':
G:\Documents\Projects\Demurr/math/DNumber.cpp:17: undefined reference to `DElement::~DElement()'
G:\Documents\Projects\Demurr/math/DNumber.cpp:17: undefined reference to `DElement::~DElement()'
G:\Documents\Projects\Demurr/math/DNumber.cpp:17: undefined reference to `DElement::~DElement()'
G:\Documents\Projects\Demurr/math/DNumber.cpp:17: undefined reference to `DElement::~DElement()'
debug/DNumber.o:G:\Documents\Projects\Demurr/math/DNumber.cpp:17: more undefined references to `DElement::~DElement()' follow

Which is stupid because


class A
{
public:
A();
virtual ~A();
};

class B : public A
{
public:
B();
virtual ~B();
};

A::A(){}
A::~A(){}
B::B(){}
B::~B(){}this compiles fine, even if I split it into separate files. It's not the pure virtuals either, I got rid of = 0 and it still fails. I wish I could spend more time developing and less time trying to fix strange errors that should not be happening. I've been trying to use Qt for some projects of mine for over a year and I finally got a project to compile only yesterday. MAPM is creating more errors but I'd like to clear up this first.

space_otter
28th February 2010, 00:46
OK, I think I'm getting a handle on this. For some reason, the Qt .pro file was missing important things like, say, the class it was complaining about being undefined. It was also missing the include directory for MAPM. Adding this information to the pro file seems to have fixed the problem. Why doesn't it do this automatically? :( I'm not impressed.

space_otter
28th February 2010, 01:01
Ack! I made a new dialog and it set the project file back! What am I doing wrong?

pitonyak
1st March 2010, 15:29
I assume that you are not placing these files in libraries, and are compiling them directly...

When you add something new, do you re-run qmake so that all of the proper files end up in the makefile? This really messed with me for a while.

space_otter
3rd March 2010, 23:26
I don't know if qmake is re-run, I'm using an IDE which re-generates the .pro file incorrectly. I need to include another library, and even though I added it to the eclipse project it deletes it from the pro file. Like I said, I'm not impressed. Anyway, I switched to Qt Creator which has some interface disadvantages but it doesn't mess up the file.

About the makefile, I'm pretty sure its not the makefile that's the problem. When I move files into different directories & add new classes it of course needs to modify the qt pro file to account for this. What would happen is that when it was done the qt pro file was wrong, it was missing essential files and my library include. When I edited the file myself everything worked.

I'm doing better now. I wanted to use eclipse because it's a fully fleshed-out IDE. But for the life of me I can't figure out how to set eclipse's compiler. I've looked everywhere, and I need to make sure it's using the right one.