[SOLVED] Force qtcreator to rebuild objects from modified template header files
-
I've asked this question here before, and never received a really satisfactory answer:
http://qt-project.org/forums/viewthread/1472I have some template classes encapsulated in .hpp files. When I make changes to those files and request a build in QtCreator 2.4, it will not rebuild the object files. So, I have to rebuild every time I make a change. Is there a way to force build dependency for headers?
Here are stripped down examples of my files. Thanks!
.pro file:
@
QT += testlibQT -= gui
TARGET = tst_somtest
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
HEADERS +=
grids/grid.hpp
grids/hexgrid.hppSOURCES +=
tst_somtest.cppDEFINES += SRCDIR=\"$$PWD/\"
QMAKE_CXXFLAGS_RELEASE += -fopenmp
QMAKE_LFLAGS_RELEASE += -fopenmp
QMAKE_CXXFLAGS_DEBUG += -g
@a .hpp file:
@
#pragma once#include <QVector>
template <class T>
class Grid
{
private:/// A set of items for the slots of the grid QVector<T> _items; // omitting additional private and protected members
public:
/// Constructs a hex grid with no size information Grid(){} /// Destructs the Grid virtual ~Grid(){} // omitting additional methods that include pure virtual functions
};
@ -
This is not a particular problem of templates, if I understand this correctly. Any change of a header file, even when you introduce a space somewhere, shall trigger a build of all modules. Shouldn't it?
-
Any modification to header file would trigger the build of those source files that include this header file. I remember in my previous project, whenever we want to modify any header file, we have to wait for a long time to get our binary.
Mostly templates would be defined in header file, so I would say any change to template or header file should trigger the build.
~veeraps
-
The problem is that there are classes that are completely encapsulated within header files. So, when the project is built, .o files for each of the template classes are generated. These .o files do not have build dependency on the .h or .hpp files. Thus, when I modify one of the template header files and then start a build in QtCreator, the associated .o is not rebuilt. This means that I either have to manually delete the .o files to force a rebuild or tell QtCreator to rebuild all. This is terrifically inconvenient, because only one class has changed but I have to rebuild everything in my project.
-
Just speaking off the cuff, as I haven't tried any of this and I'm just speculating...
If the .hpp files are self-contained classes, does it behave differently (or even work at all) if you add the .hpp files to the SOURCES variable instead of the HEADERS variable in your .pro file?
-
You might want to check the Makefile generated by qmake.
There should be a line with your source file followed by all header files included in this source file. Since you have to include your header file with those templates, this file shall show up.
AFAIK there is a difference based on the way you are including your files. There are two different syntax for your include statement.
Either
@
#include "blobla.hpp"
@
or
@
#include <blobla.hpp>
@Most people do not understand that there is a difference in behavior so. Which syntax are you using?
The first syntax should be used in your case. The second syntax is reserved for compiler headers you are not changing.
AFAIK make tools are checking this.
-
@mlong - I tried adding them to the sources, but then the compiler complains that the file format of the generated .o files are not recognized.
@koahnig - I use the first form of the include statement. The problem is that the autogenerated Makefile uses implicit dependency rules to test whether .o files should be rebuilt. In this case, it looks for extensions that indicate source files (.c, .cpp, .cxx, etc). So, my .hpp header files aren't included in the dependency checks.
-
[quote author="dusktreader" date="1334332605"]
@koahnig - I use the first form of the include statement. The problem is that the autogenerated Makefile uses implicit dependency rules to test whether .o files should be rebuilt. In this case, it looks for extensions that indicate source files (.c, .cpp, .cxx, etc). So, my .hpp header files aren't included in the dependency checks.[/quote]I had checked this on my machine after writing the post. I had set up a simple hello world program and added some includes. qmake was adding the dependency on the header files, but did not distinguish on brackets or quotation marks.
May be there is a problem with your includes path. Unfortunately, I am not experienced enough to help further.BTW: the test was done on windows 7. the program was quickly setup with msvc2005 and the .pro generated with vsaddin. And I started qmake with the .pro-filename on a command prompt.
-
@koahnig - The includes path is fine. The project builds perfectly from a clean start. It just doesn't rebuild the .o files when the headers are changed.
I build the project on Linux using g++, on windows using MinGW's toolchain.
-
I'm had exactly the same problem for quite a while. The solution was to add a line
DEPENDPATH += ...
which needs to list all the directories containing header files.
This really should be the default behaviour of Qt Creator - I can't imagine why anybody would not want all dependencies of header files to be rebuilt when they have changed.
-
[quote author="djarvie" date="1334574046"]I'm had exactly the same problem for quite a while. The solution was to add a line
DEPENDPATH += ...
which needs to list all the directories containing header files.
This really should be the default behaviour of Qt Creator - I can't imagine why anybody would not want all dependencies of header files to be rebuilt when they have changed.[/quote]
Did you check on "JIRA,":https://bugreports.qt-project.org if there is already a bug report filed?
Otherwise you should consider to file a bug report there. -
There was a bug report about this (https://bugreports.qt-project.org/browse/QTCREATORBUG-1654) which was resolved as a duplicate. However the bug which seems to be thought to be a duplicate is actually a different bug - namely that qmake is not run when Q_OBJECT is added to a header file. So closing the bug was incorrect - however, I don't know what can be done about this - or should a new bug be raised?
-
The more dependencies you have on a target, the longer it takes to build the project, as every header needs to be checked. For 3rdparty libs that you INCLUDEPATH in your project, the headers usually do not change and thus adding unnecessary load on the build process. I would advocate against including INCLUDEPATH into DEPENDPATH. If you really need that, it should just be a matter of
@
DEPENDPATH *= $${INCLUDEPATH}
@ -
@Volker - That worked, thanks! I think I will make a LOCAL_INCLUDEPATH for headers in my project, append that to INCLUDEPATH and then DEPENDPATH also. That way, the build system will only have to check local headers and not thirdparty headers.
-
Glad to be of help here. Clever to use another variable for the depending includepaths - I'll use that for my own projects.