Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Creator: linking libs from multiple projects
Forum Updated to NodeBB v4.3 + New Features

Qt Creator: linking libs from multiple projects

Scheduled Pinned Locked Moved Qt Creator and other tools
9 Posts 4 Posters 14.7k Views 1 Watching
  • 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.
  • Chris KawaC Offline
    Chris KawaC Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on last edited by Chris Kawa
    #1

    I'm a long time user of Visual Studio trying to switch to Qt Creator.
    I have a project(solution in VS) that consists of several sub-projects. Few libraries that depend on each other and a main app (exe).

    To make it simple lets consider the following file structure. This is the default layout QtCreator creates for 2 projects :

    AppMain
        appmain.pro
        main.cpp
    AppMain-build
        debug
            AppMain.exe
        release
            AppMain.exe
        Makefile etc.
    
    AppLib1
        applib1.pro
        applib1.h
        applib1.cpp
    AppLib1-build
        debug
            applib1.a
        release
            applib1.a
        Makefile etc.
    

    How do I link form the AppMain to this AppLib1?
    In the main.cpp I've included .h file like so: #include "../AppLib1/applib1.h"
    The compilation fails obviously because of the missing dependencies. How do I add this?

    In VS this was done via "Project dependencies" dialog. I found something that looks similar in QtCreator in the "Projects" pane, "Dependencies" tab, but selecting AppLib1 from the list doesn't change anything. Linker is still showing undefined references from the lib.

    There is also option to add a library in the appmain.pro file editor from the context menu by selecting "Add library...", but it only allows me to select .lib files, which I don't have since I'm using minGW (library is in .a file).

    Can I add it somehow manually by LIBS += in the .pro file? I need it to switch between the debug and release applib1.a file, and the paths can't be absolute because this project is in version control used on several machines.

    I'm using RC of Qt Creator 2.1 with minGW on Windows7 x64

    Any help will be great.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      blex
      wrote on last edited by Chris Kawa
      #2

      You should add manually to the .pro file something like this:

      debug:LIBS+=debug_library_file_name
      release:LIBS+=release_library_file_name
      

      Also you should set "Dependencies" in the "Projects" pane.

      You may use session (menu File - Session) to save the settings and load them on next run.

      I am not sure what exactly "library_file_name" is on Windows, probably it is "library_file_name.a"

      Path in library_file_name may be relative.

      Also see this post: https://developer.qt.nokia.com/forums/viewthread/1913


      Oleksiy Balabay

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #3

        I ended up with something like this:

        debug: LIBS += -L"../AppLib1-build/debug"
        release: LIBS += -L"../AppLib1-build/release"
        LIBS += -lApplib1
        

        Wow, I can see now that the transition from VS will be super-confusing for me (the project is quite large), all this manual "configuration" work..

        Anyway, thanks a lot blex.
        One question though - what exactly does checking projects in "Dependencies" tab do? It doesn't seem to matter if it's checked or not in my case.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          blex
          wrote on last edited by
          #4

          [quote author="crossblades" date="1290890172"]
          One question though - what exactly does checking projects in "Dependencies" tab do? It doesn't seem to matter if it's checked or not in my case.[/quote]

          I think it is build order


          Oleksiy Balabay

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            [quote author="crossblades" date="1290890172"]I ended up with something like this:
            @debug: LIBS += -L"../AppLib1-build/debug"
            release: LIBS += -L"../AppLib1-build/release"
            LIBS += -lApplib1
            @
            [/quote]

            You also can add this to shorten the includes:
            @
            INCLUDEPATH += ../Applib1
            @

            Then this include works:
            @
            #include "applib1.h"
            @

            [quote author="crossblades" date="1290890172"]I ended up One question though - what exactly does checking projects in "Dependencies" tab do? It doesn't seem to matter if it's checked or not in my case.[/quote]

            If you set it up, the build order is calculated correctly and if you modify the lib the app is relinked afterwards to pick up the changes. If you don't you might end up with an old application that is not linked against the new build of your lib.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on last edited by
              #6

              I would suggest turning both library and application into one project by adding another .pro-file using the SUBDIRS template. That is a way to wrap many .pro-files into one project.

              Using this combined project it is way more straight forward to set library and include pathes.

              If you only rarely work on the library and do not want to have it open in creator all the time then you might want to consider to properly install the library in your system... that makes working with it way easier, too.

              1 Reply Last reply
              0
              • Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Thanks for all replies.
                My whole project consists of several "base" libraries and a few exe projects - something similar to Qt - some base libs are held in QtCore, QtGui etc and bunch of executables share this base (Creator, Designer, Linguist..), except they're statically linked by default.

                I'll look into the suggested SUBDIRS template. From Your description this looks like something that might be useful to me.
                Btw are there any good docs to the .pro files format? I can't seem to find any "oficial" spec, so I'm learning by going through Qt srcs, but it's hard if You don't exactly know what You're looking.

                At this beginning stage all of the components are changing/growing often. I usually have all or almost all of them opened at the same time.
                What do you mean by properly installing the libs? I don't think there is any standard way to "install" a library(.a or .lib) in windows, except for maybe adding it to the environment path, but I don't need that.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  You can find the complete documentation "here":http://doc.qt.nokia.com/4.7/qmake-manual.html. The same content is provided in Qt Assistant, btw.

                  I think Tobias meant "installing" in the sense of installing it (a DLL probably) into some system directory. But from what you've writte this seems not to be the solution for you.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Thanks! I'm really scratching my head how could I miss that.

                    1 Reply Last reply
                    0

                    • Login

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