4

[Updated]

When changing a specific source file, at building the project compilation takes approx. 10 minutes. Changes of other source files lead to more or less instant build times. I figured that if I move the most changed parts to a pimpl class, the compile time is no longer affected.

I do not understand why this is the case. I did not change the header file of the class. The header itself does only #include <QWidget> and forward declares 10 classes. What reasons could there be that lead to recompilation (in the build directory I see all object files regenerated) when changing a source file that is nowhere directly included? It is strange that the pimpl works then...

Here is the header of the class:

#ifndef EXPLORER_H
#define EXPLORER_H

#include <QWidget>

... here coming 10 forward declared classes ...

class Explorer : public QWidget
{
    Q_OBJECT
public:
    explicit Explorer(QWidget *parent = 0);
    ~Explorer();
signals:
    ...    
public slots:
    ...
private:
    ExplorerPrivate *p; // pimpl (QObject)
    ...pointers to objects of forward declared classes
};

#endif // EXPLORER_H

EDIT

  • Building with QtCreator 3.2.1

  • Using Qt5.3 with mingw

  • As I said the cpp file is nowhere included (searched for it)

  • qmake.exe project.pro -r -spec win32-g++ "CONFIG+=debug"

  • Make: mingw32-make.exe

The compiler console spits out endless repetitions of g++ -c -pipe -fno-keep-inline-dllexport -O2 -std=c++0x -frtti -Wall -Wextra -fexceptions -mthreads [include flags and directories here] and at the end something like -o objects\moc_runtimedata.o moc\moc_runtimedata.cpp or similar.

user2366975
  • 4,350
  • 9
  • 47
  • 87
  • 4
    What IDE/build system? Also, the crystal ball says that the .cpp file might me `#include`d into an another .cpp somewhere else. – HolyBlackCat Jul 16 '16 at 22:01
  • 4
    Code doesn't just spontaneously compile itself. How are you running the compiler? – melpomene Jul 16 '16 at 22:03
  • "How are you running the compiler" is the edit clear enough? I just installed QtCreator, did not change default compiler parameters. – user2366975 Jul 17 '16 at 18:40
  • Qt creator shows how many file get recompiled every time you build ... did you check that number ? – HazemGomaa Oct 14 '16 at 23:45
  • Please, where do you find that number? – user2366975 Oct 15 '16 at 06:57
  • Stop downvoting without constructive criticism! To HolyBlackCat upvoters: I answered long ago that the file is not included directly! Only the header! I also added the IDE and the build system so please move on... – user2366975 Oct 15 '16 at 20:22
  • You can find the number of files which are recompiled in the window "Compile output" (look at the bottom of your ide). – user1482030 Oct 19 '16 at 13:48
  • Not for me. The last lines are: `mingw32-make[1]: Leaving directory 'G:/SoftwareDev/projects/myapp/pc/code/build/debug' 19:16:00: Der Prozess "C:\Qt\Qt5.3.2\Tools\mingw482_32\bin\mingw32-make.exe" wurde normal beendet. 19:16:00: Verstrichene Zeit: 00:10.` – user2366975 Oct 19 '16 at 17:36
  • Have you checked the timestamp (time of creation/modification) of your source files. If for some reason your source file timestamp is in the future, QtCreator will always believe the object files are older and need to be recompiled. – jpo38 Oct 20 '16 at 19:24
  • Also, did you try to disable shadow build? I experienced cases where they fall down in infinite loop, always rebuilding the same project again and again (that's a Qt known issue, maybe you're experiencing something similar). – jpo38 Oct 20 '16 at 19:26
  • @jpo38: **1st point:** timestamp comparison showed that almost all files are getting recompiled. I should mention that I could drop the compile time from 10 minutes to 2 minutes with compiling with flag `-j 8` to utilize multiple cores for o-file creation. **2nd point:** I disabled shadow build as you suggested. Not so nice because all files are now in src dir, BUT: **it works!** 10 seconds. Can't believe it (I also made a fresh shadow build; long compile time again). Thanks a lot! :) Do you know if this has been fixed for Qt versions > 5.3? – user2366975 Oct 20 '16 at 21:29
  • @user2366975: Dunno. Posted an answer as that fixed your problem. You may want to try with a more recent version of QtCreator (I use 4.0.3) – jpo38 Oct 21 '16 at 10:16

1 Answers1

0

QtCreator has a bug when shadow builds are enabled. Not sure this was reported to Qt as it's hard to reproduce.

When this shadow build option is activated (default), the IDE sometime will fail to realize some projects are up to date and will build them even if sources are unchanged. I'm experiencing this often with huge projects having lots of .pro files, it my case, the project is not only built when it should not, it's rebuilt again and again in an endless loop.

Even if that's annoying because output files could get mixed with source files and also switching between Release/Debug will always require a clean build (as Release and Debug files are being generated in the same folder), disabling "Shadow build" fixes the issue.

Other people experiencing this: https://forum.qt.io/topic/30086/endless-loop-of-qmake-exe, http://www.qtcentre.org/threads/59963-a-simple-project-with-quot-Infinite-building-quot or Qt Creator error endless loop

Here people report endless loop, you were lucky you did not end up with that...

Community
  • 1
  • 1
jpo38
  • 20,821
  • 10
  • 70
  • 151
  • On the "upside" of rebuilding unchanged files, it also often seems to forget to build changed. Thus the occasional "clean/qmake/rebuild" routine :D – dtech Oct 21 '16 at 12:48
  • @ddriver: Sure, saw that too, specially when modifying .ui or .qrc, they sometime never get recompiled into header files... – jpo38 Oct 21 '16 at 12:57
  • IMHO, dump qmake for anything project that is more than a couple of T.U. The amount of bugs, inconsistencies, and undocumented functionalities is just too big. QtCreator supports cmake just fine, just stick with that. – sbabbi Oct 21 '16 at 15:32