Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    [SOLVED] How to manage include paths

    General and Desktop
    2
    3
    1930
    Loading More Posts
    • 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.
    • D
      DRoscoe last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • D
        DRoscoe last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • PeteC
          PeteC last edited by

          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.

          pac

          1 Reply Last reply Reply Quote 0
          • First post
            Last post