PDA

View Full Version : Problem: Undefined reference



stiank81
16th February 2006, 13:25
I'm using an external class witch I've made myself together with a QT-form, but when I'm running make to compile the program I get errors on “Undefined reference” for every place I'm using the included class. I can't understand why...

The way I've built up the program is that I have a project witch has a form. Inside the form I include my class, TestCls. I know that the file is included. It compiles as long as I just include it(but don't use it), and also classes refered by this class is compiled. I've also seen proof elsewhere that the class is included. But still I get this “undefined reference” everywhere I try to use it.

Here is the code in Form.ui.h:

#include "TestCls.h"
void Form::testSlot(){
TestCls tsst = TestCls();
double nmbr = tsst.getTest();
lineEdit_result->setText(QString::number(nmbr, 'g', 4));
}

Witch gives me “undefined reference” on both the creation of tsst and getTest().
Any suggestions??


Best Regards,
Stian

zlatko
16th February 2006, 13:32
have you include TestCls.cpp in your *.pro file?

Bojan
16th February 2006, 13:37
If I understand correctly, TestCls is your own class, that you created yourself, and are trying to use it in a Qt-designer created form. Undefined reference is usually a linker error, when the linker can't find the object code, or the actual implementation (definition) of classes, methods, functions, etc... (or something like that, not completely sure).

So I am guessing you have TestCls.h and TestCls.cpp. In your TestCls you declare your classes and functions, and in the .cpp file you define them. Make sure you actually implement everything declared in your TestCls.h file in your TestCls.cpp file. Then also make sure that in your project file, TestCls.h is listed under HEADERS, and TestCls.cpp is listed under SOURCES. Then try a make clean, qmake, make.

If this doesn't work, please provide more information, such as your .pro file, and what platform you are using and how you are building this, and more details how files are orginised.

Bojan

stiank81
16th February 2006, 13:57
Thanks both of you.
Bojar, you are right about your assumtions, but everything is correct here.

I think zlatko found the right answer; no, I haven't included the cpp-files in my project-file. As you probably understand I'm new to Qt, so I didn't know that I had to. I've included them now, and it works for this testexample. Now, another problem for my real program:
I don't just have c++files. I also have some assemblyfiles, .asm. I tried to put this is with
SOURCES += theFile.asm
, but this didn't work. I see that also the language is specified. Can I specify a section with assembly source code files?
LANGUAGE = ASSEMBLY
SOURCES += theFile.asm
, or something like this?..

-Stian

stiank81
16th February 2006, 14:17
Never mind, I figured it out.

Instead of including the source for the assembly file I compiled it myself and included the object file, .o, by writing
OBJECTS += theFile.o

Now it's working. Thanks!