PDA

View Full Version : INCLUDEPATH how it works ?



tonnot
27th October 2010, 19:19
If I have a correct path at INCLUDEPATH, why is the reason because I have undefined reference errors for certain h files located at this path ? It is solved if I add the file 'by hand'.
And... I imagine that I could have different versions of files, and I only would have to change the INCLUDEPATH to use one or other, but I think it does not going to work ...
Any explanation ? Thanks

wysota
27th October 2010, 19:56
"h" files have nothing to do with unresolved reference errors.

bred
27th October 2010, 19:59
Post your .pro file in the forum.
It seems to be an editing error.


"h" files have nothing to do with unresolved reference errors.
Ops. you have right.


------------
Probably you have forgotten some to edit the LIBS variable or to add some dll or obj.
http://doc.trolltech.com/4.7/qmake-variable-reference.html#libs

tonnot
27th October 2010, 20:09
This is the pro file :


QT += core gui

TEMPLATE = app
CONFIG += qt debug_and_release


TARGET = gui_plu


INCLUDEPATH += ../AnalogWidgets/analogwidgets/analogwidgets \
../AnalogWidgets/analogwidgets/code

HEADERS += form.h \
../AnalogWidgets/analogwidgets/analogwidgets/wallclock.h \
../AnalogWidgets/analogwidgets/analogwidgets/widgetwithbackground.h \ (<<< the line I delete ... )
../AnalogWidgets/analogwidgets/analogwidgets/led.h \
../AnalogWidgets/analogwidgets/plugins/led_plugin.h \
../AnalogWidgets/analogwidgets/plugins/wallclock_plugin.h

SOURCES += form.cpp \
main.cpp \
../AnalogWidgets/analogwidgets/code/wallclock.cpp \
../AnalogWidgets/analogwidgets/code/widgetwithbackground.cpp \
../AnalogWidgets/analogwidgets/code/led.cpp \
../AnalogWidgets/analogwidgets/plugins/wallclock_plugin.cpp \
../AnalogWidgets/analogwidgets/plugins/led_plugin.cpp

FORMS += \
form.ui


If I delete ../AnalogWidgets/analogwidgets/analogwidgets/widgetwithbackground.h \ i have :

../AnalogWidgets/analogwidgets/code/widgetwithbackground.cpp:26: undefined reference to `vtable for WidgetWithBackground'
../AnalogWidgets/analogwidgets/code/widgetwithbackground.cpp:26: undefined reference to `vtable for WidgetWithBackground'
../AnalogWidgets/analogwidgets/code/widgetwithbackground.cpp:26: undefined reference to `vtable for WidgetWithBackground'
../AnalogWidgets/analogwidgets/code/widgetwithbackground.cpp:26: undefined reference to `vtable for WidgetWithBackground'
debug/widgetwithbackground.o: In function `~WidgetWithBackground':
../AnalogWidgets/analogwidgets/code/widgetwithbackground.cpp:32: undefined reference to `vtable for WidgetWithBackground'
../AnalogWidgets/analogwidgets/code/widgetwithbackground.cpp:32: more undefined references to `vtable for WidgetWithBackground' follow
plug1-build-desktop/debug/moc_wallclock.cpp:89: undefined reference to `WidgetWithBackground::qt_metacast(char const*)'
plug1-build-desktop/debug/moc_wallclock.cpp:94: undefined reference to `WidgetWithBackground::qt_metacall(QMetaObject::Ca ll, int, void**)'
debug/moc_wallclock.o:moc_wallclock.cpp:(.rdata+0x0): undefined reference to `WidgetWithBackground::staticMetaObject'
plug1-build-desktop/debug/moc_led.cpp:71: undefined reference to `WidgetWithBackground::qt_metacast(char const*)'
plug1-build-desktop/debug/moc_led.cpp:76: undefined reference to `WidgetWithBackground::qt_metacall(QMetaObject::Ca ll, int, void**)'
debug/moc_led.o:moc_led.cpp:(.rdata+0x0): undefined reference to `WidgetWithBackground::staticMetaObject'
collect2: ld returned 1 exit status


( This file is used by led.h and wallclock.h (#include "widgetwithbackground.h"))

wysota
27th October 2010, 20:17
Rerun qmake.

tonnot
27th October 2010, 20:23
I'm using QT Creator ...

wysota
27th October 2010, 20:27
Then rerun qmake under Qt Creator.

Leszek
27th October 2010, 20:27
Press Right Mouse button -> clean project -> Run qmake. Should working.

bred
27th October 2010, 20:30
I'm using QT Creator ...

main menu > build > run qmake

tonnot
27th October 2010, 20:30
Qmake does :

Starting: "d:/qt/2010.04/qt/bin/qmake.exe" d:/c++/plug1/plug1.pro -r -spec win32-g++
The process "d:/qt/2010.04/qt/bin/qmake.exe" exited normally.
And nothing more... (My application is not launched)
Then, if I do click on 'run' project all the building process is launched again with the same errors.

wysota
27th October 2010, 20:34
Tonnot, please do me a favour. Go through the basic Qt programming tutorial available in Qt documentation. Then get a decent book on C++ programming and read it. We're not here to teach you programming. And you obviously lack the basic knowledge regarding software development.

tonnot
27th October 2010, 20:39
Yes, because of it I am here (newbie)
Sincerely, I dont know what is happen.
And my main question (the errors I get If I have the INCLUDEPATH ok but not have the .h file added at .pro file) is still without solution ...
Thanks

wysota
27th October 2010, 20:50
This is a Qt forum. We're helping with Qt issues. Not with I-don't-know-how-to-program issues. The "newbie" forum is for Qt newbies, not programming newbies. You have to learn by yourself how a compiler works, what are include files, etc.

tonnot
27th October 2010, 20:57
Excuse me, but I think that I am not making so basic questions.
Of course, I'm learning c++ but I am not asking about how to declare a variable....

And my main question (the errors I get If I have the INCLUDEPATH ok but not have the .h file added at .pro file) is still without solution ...
Thanks

wysota
27th October 2010, 21:06
Excuse me, but I think that I am not making so basic questions.
Of course, I'm learning c++ but I am not asking about how to declare a variable....
Ok, I'll treat you as a "programming grown-up" then.

Your problem is the implementation of the offending functions is provided by a precompiler that is ran on header files in search of the Q_OBJECT macro. Classes containing the macro are then scanned for keywords and definitions that later form the meta-object for the class which should then be included in the compilation and linked with the rest of object code. If qmake handles your build process then it pre-scans all files added to the variable containing the list of headers and if Q_OBJECT is spotted in any of them, the file is fed to moc and its result included in the compilation. So to solve your problem you need to make sure that moc preprocesses the files and its result is included in the rest of the compilation.

Leszek
27th October 2010, 21:12
Uppps Sorry I didn`t see answer from wysota.... :)

but not have the .h file added at .pro file) is still without solution ...


Qmake is kind of tool which can generate Makefiles. When you see into your build folder, there are files like Makafile.Debug, Makafile.Release(propably).
In that files there is a "kind of informction" what will be compiled and how(See ####### Compile). Maybe you should analyze this file, than some problems with compilation will be more clearly, maybe ;)

ChrisW67
27th October 2010, 23:35
If I delete ../AnalogWidgets/analogwidgets/analogwidgets/widgetwithbackground.h \ i have :
Why would you do that if:


This file is used by led.h and wallclock.h (#include "widgetwithbackground.h")

and presumably also by widgetwithbackground.cpp.

By removing this file, containing a Q_OBJECT macro, from HEADERS you are telling Qt that it doesn't need to run moc (or anything else) on this file... so it doesn't. This means that the code moc generates on your behalf is not generated, which includes the "vtable" referenced in the error messages from your linker.

The INCLUDEPATH tells the C++ compiler how to find headers other than those in default locations, which it is clearly doing or your code would not compile. It has no bearing on moc.

In short, if you deliberately break it then you get to keep the pieces.

tonnot
28th October 2010, 10:09
This is the text showed by the QT HELP:

INCLUDEPATH
This variable specifies the #include directories which should be searched when compiling the project. Use ';' or a space as the directory separator.

So, finally ... INCLUDEPATH fails with #include's ?
Thanks for the answers (specially from then last 3 )

wysota
28th October 2010, 10:16
No, it doesn't fail with anything. It's just a place where to look for header fiiles. Your problem is not that some header files were not found.

tonnot
28th October 2010, 10:34
Thanks, WY (and sincerely thank you very much for your patience)
So finally, If you are going to use some custom widgets (using promoting aproach) be carefull to add 'by hand' all the dependant files, isn't it ?
Thanks again

wysota
28th October 2010, 10:55
Using custom widgets "using promoting approach" is no different than using them directly in hand-written C++ code. You always need to add the header and implementation file (provided they exist) to the project.

ChrisW67
28th October 2010, 23:49
INCLUDEPATH
This variable specifies the #include directories which should be searched when compiling the project. Use ';' or a space as the directory separator.

Notice the words "when compiling the project". That is to say, the paths are sent to the C++ compiler as -I options or their equivalent. There a literally hundreds of include files involved in compiling your project, many (most) of which have nothing directly relating them to Qt. Qt does not assume that every possible include file is part of your project and does not scan every one of these files for the Q_OBJECT or other markers that trigger Qt code generation. Qmake uses the HEADERS variable to identify files that are part of your project and should be scanned for pre-processing triggers and, when found, generate and compile extra C++ source on your behalf.

In your case the C++ compiler is finding everything it needs to compile the project. The linker fails because code that is generated on your behalf has not been generated and included in the compilation, i.e. HEADERS is wrong.

tonnot
29th October 2010, 10:22
I understand your explanation.
At end, Is there any way to say QT that must investigate for Q_Object and other markes ?
Thanks

wysota
29th October 2010, 10:53
I understand your explanation.
At end, Is there any way to say QT that must investigate for Q_Object and other markes ?
Thanks

Read this sentence again:

The linker fails because code that is generated on your behalf has not been generated and included in the compilation, i.e. HEADERS is wrong.