Reusing compiled objects between compilation of subdir projects
-
Hello,
I have a large C++ project that has a lot of unit tests each represented as a separate project in its own folder. These are tied together using the QMake subdirs directive, and everything works just fine for compiling and running the tests. I do have one big problem though, and that is the speed of the compilation. It takes forever :)
The unit tests use a lot of common code to get started, and I've seen that they all compile the same files over and over again. I therefore attempted to use the OBJECTS_DIR and MOC_DIR variables to make sure that they store their binary files in the same place (while using CONFIG += ordered to avoid clashes). This doesn't work though. It takes the same amount of time to compile because each test project recompiles all files, even though the compiled versions are right there in the OBJECTS_DIR.
What am I doing wrong? Is it at all possible to re-use the object files between compiles of the different unit test projects?
Best regards,
Mads -
Hello,
I have a large C++ project that has a lot of unit tests each represented as a separate project in its own folder. These are tied together using the QMake subdirs directive, and everything works just fine for compiling and running the tests. I do have one big problem though, and that is the speed of the compilation. It takes forever :)
The unit tests use a lot of common code to get started, and I've seen that they all compile the same files over and over again. I therefore attempted to use the OBJECTS_DIR and MOC_DIR variables to make sure that they store their binary files in the same place (while using CONFIG += ordered to avoid clashes). This doesn't work though. It takes the same amount of time to compile because each test project recompiles all files, even though the compiled versions are right there in the OBJECTS_DIR.
What am I doing wrong? Is it at all possible to re-use the object files between compiles of the different unit test projects?
Best regards,
Mads@Mads-D.-K.
hi, I can't help directly - not enough experience - but, just to make sure, do you pass additional arguments tomake
? bumping the number of jobs from default 1 to at least the number of cores of your pc decreases the needed time for compilation greatly. -
Thanks for your reply. Yes, I do compile multiple files in parallel - make -j8 on Linux and jom -j8 on Windows. That does help a lot :) My problem is that much of my code is recompiled ~100 times.
-
That sounds like a very good usecase for a shared library... When the code is shared - why don't you create a shared lib instead adding it to every application/library?
-
That sounds like a very good usecase for a shared library... When the code is shared - why don't you create a shared lib instead adding it to every application/library?
@Christian-Ehrlicher Thank you for your answer. True, I could build a shared lib, but there is really only one application. The problem is that each unit test works as its own "application", so it's only for the unit tests that I need this.
-
Ok, if you need it for unit tests only I would go with a static library.