I have a project for which I regularly modify headers and when I do so, and forget to make clean
then make
, I get all sorts of weird behavior. I'm currently using Qt Creator as my IDE, but I've seen this happen on a Qt-independent project. My project is getting fairly large, and having to rebuild every time I make a header change is becoming unproductive. Any thoughts?
For future reference:
If using the QMake system:
DEPENDPATH += . \ HeaderLocation1/ \ HeaderLocation2/ \ HeaderLocation2/HeaderSubLocation1/ \ HeaderLocation2/HeaderSubLocation2/ \ HeaderLocation2/HeaderSubLocation3/ \ HeaderLocation2/HeaderSubLocation4/ \ HeaderLocation2/HeaderSubLocation5/ \ HeaderLocation3/ \ HeaderLocation3/HeaderSubLocation1/ \ HeaderLocation3/HeaderSubLocation2/ \
The solution is to have proper header dependency's in your makefile.
1) Use makedepend to generate the dependency files. You would add a target to your makefile which regenerates the dependency file, and you'd want to invoke that before actually doing your compilation. 2) GCC only: Use '-MMD' and '-MP' options on your compile line for .c/.cpp files. This causes GCC to generate a dependency file for input file. Then, you can include these in your makefile. The advantage here is that with those two options, as you add and remove headers, it should behave as you expect.
This is mainly caused by dependencies between files. So if you alter a .h file which is included in another, that file will also need to be recompiled. So either you need to reduce your includes, or do your coding in .h/.cpp form when possible to make changes in .cpp more often than .h.
Re-run
qmake
. This will generate a new Makefile which will have proper dependencies.Example:
A file
file.h
looking like the following:and
file.cpp
looking like the following:and having in your
.pro
:will produce the following in the resulting
Makefile
:Dont know anything about your IDE, and not sure if its relevant, and since you are not including your makefile - I'll just state the obvious - do you use any auto-generated dependencies?
For g++ I use the
-MD
flag, then in the makefile include$(wildcard bin/*.d)
(depending on where your object file is created, mine are created in 'bin')Also make sure to delete the dep file on a clean build
Here is an excerpt from my own makefile generating and using dependency files automatically created during compilation. You would have to make an additional entry for cpp files
Dont forget to add delete *.d files on clean build