[SOLVED] How to manage include paths



  • My main project is a Qt 5.4 Quick application which uses several legacy C++ libraries. I want Qt to build the library targets as part of my application, but the source code for the libraries is outside of my build tree. The only way I can find to do this involves adding the files to my project. Using the "Add existing directory" wizard, I started out adding the directories I want to build. Each directory contains all of the code for each library I am trying to build. This did not work. I could not control the order in which files where compiled, nor could I specify the build targets, which in this case are static libs. Looking through the documentation, it seemed to me a better option would be to set the main project as a SUBDIRS project and add each library as a sub-project. So here is what I ended up with:

    Application (subdirs project)

    • library1 (static c++ sub project)
    • library2 (static c++ sub project)
    • library3 (static c++ sub project)

    The above is a simplified representation. The Application has a dependency on library3, and library3 depends on library1 which depends on library2. There are no circular dependencies.

    To each sub-project, I used "Add existing directory" to pull in the source files. So far, so good.

    The next problem I have is include directory search paths. Library3 does not know where to find header files for Library1. I am not an expert on Qmake, so I am avoiding manually editing the PRO file. The only way I found to give Library3 knowledge of Library1 was to use the Add Library wizard on Library3, adding Library1 as an INTERNAL library to Library3. This seems to get me over the first hurdle and specifies a dependency. This arrangement almost makes sense. The next problem, however, does not.

    As I mentioned above, Library3 depends on Library1 which depends on Library2. When I add Library1 to Library3, I solve the immediate problem of include directories with Library1, but when I try to build Library3, I get file not found errors from files in Library2. This does not seem right to me. Library3 does not care about files from Library2. By including Library1, I assumed it was actually bootstrapping the PRO file for Library1, which reconciles its own dependencies on Library2. What I expected to happen was that Library3 would bootstrap Library1 which would bootstrap Library2, causing it to be built. Then Library1 would be built, linking in Library2, and finally, Library 3 would build and link in Library1

    This is a basic problem that I have solved many times on other platforms, but I can't seem to figure out the "Qt Creator Way". I know this can't be a unique situation.



  • UPDATE: Looks like I need to read the documentation. I found the variables documentation:

    "Qt5 Variable Reference":http://doc.qt.io/qt-5/qmake-variable-reference.html

    and it looks like there is a way to do what I need easily. The problem is, its not available through Qt Creator, so you HAVE to modify the PRO file manually to specify dependencies. My trick of adding the libraries to other libraries is the wrong way to go and created the directory search issue.

    If you look at the subdirs documentation, you will see how to do it properly. I am providing my own answer here in case anyone else has a similar problem.



  • I had the same linking problem with a c++ project using a custom built clang compiler on OSX Mavericks using QT 5.4.

    It turned out to be that I was compiling with a c compiler (clang) instead of the c++ compiler (clang++)

    By adding

    CMAKE_CXX=clang++

    into all the library pro files and recompiling and then the same for the application everything linked successfully.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.