title: How to create layered project structure in c++ using qmake
body: <p>Under windows using MinGW, C++11, Qt 5 and qmake I have following project structure:</p>
  
  <pre><code>/my-project
     my-project.pro
     /my-app
        my-app.pro
        main.cpp
     /module-a
        module-a.pro
        modulea.h
        modulea.cpp
     /module-b
        module-b.pro
        moduleb.h
        moduleb.cpp
  </code></pre>
  
  <p>The dependencies between modules should look like this:</p>
  
  <pre><code>my-app ==&gt; module-a ==&gt; module-b
  </code></pre>
  
  <p>What I want to achieve is that my-app uses module-a, module-a uses module-b and my-app doesn't know anything about module-b. The module-a references module-b only through its implementation (the <code>#include</code> for module-b is located in .cpp of module-a).</p>
  
  <p>I've tried to implement this by configuring module-a and module-b as static libraries in qmake. Unfortunately while compiling I receive linker error saying 'undefined reference to ModuleB::doSmthB()'</p>
  
  <p>I understand the reason of this linking problem, my question is if it is somehow possible to achieve something similar to the proposed layered structure?</p>
  
  <p>Sources:</p>
  
  <p>my-project.pro:</p>
  
  <pre><code>TEMPLATE = subdirs
  SUBDIRS += module-b
  SUBDIRS += module-a
  SUBDIRS += my-app
  my-app.depends = module-a
  module-a.depends = module-b
  </code></pre>
  
  <p>my-app.pro:</p>
  
  <pre><code>QT += widgets
  TARGET = my-app
  TEMPLATE = app
  CONFIG += c++11
  SOURCES += *.cpp
  win32 {
      INCLUDEPATH += $$clean_path($$PWD/../module-a)
      DEPENDPATH += $$clean_path($$PWD/../module-a)
      LIBS += $$clean_path($$OUT_PWD/../module-a/debug/libmodule-a.a)
      PRE_TARGETDEPS += $$clean_path($$OUT_PWD/../module-a/debug/libmodule-a.a)
  }
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QGraphicsView&gt;
  #include &lt;QGraphicsScene&gt;
  
  #include "modulea.h"
  
  int main(int argc, char *args[])
  {
      QApplication app(argc, args);
      QGraphicsView view;
      QGraphicsScene *scene = new QGraphicsScene(0, 0, 300, 300, &amp;view);
      ModuleA moduleA;
      scene-&gt;addText(QString::number(moduleA.doSmthA())); // undefined reference to ModuleB::doSmthB()
      view.setScene(scene);
      view.show();
      return app.exec();
  }
  </code></pre>
  
  <p>module-a.pro:</p>
  
  <pre><code>QT -= core gui
  TARGET = module-a
  TEMPLATE = lib
  CONFIG += staticlib
  CONFIG += c++11
  HEADERS += *.h
  SOURCES += *.cpp
  win32 {
      INCLUDEPATH += $$clean_path($$PWD/../module-b)
      DEPENDPATH += $$clean_path($$PWD/../module-b)
      LIBS += $$clean_path($$OUT_PWD/../module-b/debug/libmodule-b.a)
      PRE_TARGETDEPS += $$clean_path($$OUT_PWD/../module-b/debug/libmodule-b.a)
  }
  </code></pre>
  
  <p>modulea.h:</p>
  
  <pre><code>#ifndef MODULEA_H
  #define MODULEA_H
  
  struct ModuleA
  {
      int doSmthA();
  };
  
  #endif // MODULEA_H
  </code></pre>
  
  <p>modulea.cpp:</p>
  
  <pre><code>#include "modulea.h"
  #include "moduleb.h"
  
  int ModuleA::doSmthA() {
      ModuleB other;
      return other.doSmthB();
  }
  </code></pre>
  
  <p>module-b.pro:</p>
  
  <pre><code>QT -= core gui
  TARGET = module-b
  TEMPLATE = lib
  CONFIG += staticlib
  CONFIG += c++11
  HEADERS += *.h
  SOURCES += *.cpp
  </code></pre>
  
  <p>moduleb.h:</p>
  
  <pre><code>#ifndef MODULEB_H
  #define MODULEB_H
  
  struct ModuleB
  {
      int doSmthB();
  };
  
  #endif // MODULEB_H
  </code></pre>
  
  <p>moduleb.cpp:</p>
  
  <pre><code>#include "moduleb.h"
  
  int ModuleB::doSmthB() {
      return 12345;
  }
  </code></pre>