Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reusing compiled objects between compilation of subdir projects
QtWS25 Last Chance

Reusing compiled objects between compilation of subdir projects

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 624 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mads D. K.
    wrote on last edited by
    #1

    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

    J.HilkJ 1 Reply Last reply
    0
    • M Mads D. K.

      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

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @Mads-D.-K.
      hi, I can't help directly - not enough experience - but, just to make sure, do you pass additional arguments to make? 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.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mads D. K.
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          M 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            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?

            M Offline
            M Offline
            Mads D. K.
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Ok, if you need it for unit tests only I would go with a static library.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved