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. Library reference in project?
Forum Updated to NodeBB v4.3 + New Features

Library reference in project?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
6 Posts 2 Posters 1.7k Views 2 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.
  • T Offline
    T Offline
    treaves
    wrote on 3 May 2016, 19:44 last edited by
    #1

    I'm adding attests to a Qt Quick project. Looks like the preferred way to do this is to put all C++ into a lib, and link it to the main.cpp with the UI stuff. And link to the test target. This is unfortunate, but, that's that. The issue is how to link to the library?

    This is all within a single Qt Creator project using qmake. The build system really should know where it's putting things, and handle those paths automatically. But it doesn't. As I'm searching the web, I'm seeing all kinds of convoluted .pro & pro files, at each directory level, to resolve where the library is, and setting up the linker flags.

    Is Qt Creator really this - broken? My default project, created in creator, for a single test, has three targets, with each target having three output directories (debug, profile, release). That's a lot to maintain, especially for someone coming from Xcode .

    Any help appreciated.

    K 1 Reply Last reply 4 May 2016, 06:42
    0
    • T treaves
      3 May 2016, 19:44

      I'm adding attests to a Qt Quick project. Looks like the preferred way to do this is to put all C++ into a lib, and link it to the main.cpp with the UI stuff. And link to the test target. This is unfortunate, but, that's that. The issue is how to link to the library?

      This is all within a single Qt Creator project using qmake. The build system really should know where it's putting things, and handle those paths automatically. But it doesn't. As I'm searching the web, I'm seeing all kinds of convoluted .pro & pro files, at each directory level, to resolve where the library is, and setting up the linker flags.

      Is Qt Creator really this - broken? My default project, created in creator, for a single test, has three targets, with each target having three output directories (debug, profile, release). That's a lot to maintain, especially for someone coming from Xcode .

      Any help appreciated.

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 4 May 2016, 06:42 last edited by kshegunov 5 Apr 2016, 06:44
      #2

      @treaves said:

      The issue is how to link to the library?

      What kind of linking is that - static or dynamic?

      This is all within a single Qt Creator project using qmake.

      What is? If you're going to link a library then you should have two projects - one for the library and one for the application. Am I missing something here?

      Is Qt Creator really this - broken?

      For one Qt Creator is separate from the build system and most certainly is not broken. Perhaps you could provide some parts (or the whole) project file so you could attract some suggestions? I'll give you an example of a recent project how I build my own library and then link it (note that it's shadow-built):

      myapplication.pro

      QT += core network sql serialport xml
      QT -= gui
      
      TEMPLATE = app
      
      CONFIG += c++11 console
      CONFIG -= app_bundle
      
      INCLUDEPATH += ../qdaemon
      LIBS += -L. -lqdaemon
      
      MAKEFILE = ...
      
      # ... and so on ...
      

      qdaemon.pro

      QT += core
      QT -= gui
      
      unix:!macx  {
      	QT += dbus
      }
      
      macx|win32  {
      	error("This library is currently not supporting your platform.")
      }
      
      TARGET = qdaemon
      TEMPLATE = lib
      
      CONFIG += c++11
      
      DEFINES += QDAEMON_LIBRARY
      
      MAKEFILE = qdaemon.make
      
      # ... and so on ...
      

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        treaves
        wrote on 11 May 2016, 13:54 last edited by
        #3

        The library import as you show it seems to work for the application, but, not for the tests. This is just a standard project created from the Qt Creator template for AutoTests.

        In the AutoTest, the structure is:

        ./master.pro
        ./app/app.pro
        ./lib/lib.pro
        ./tests/tests.pro
        ./tests/test1/test1.pro
        ./tests/test2/test2.pro

        I have the LIBS & INCLUDEPATH in both app.pro and test1.pro. In test1.pro the path is ../../lib instead of just ../lib as it is in app.pro. But the library is still not found.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          treaves
          wrote on 11 May 2016, 13:59 last edited by
          #4

          I misspoke. app does not see the library either.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            treaves
            wrote on 11 May 2016, 14:01 last edited by
            #5

            I'm using shadow builds too. Nothing in the compile output shows that qmake is using the correct path the the library. The path to the library will depend on if the build is debug, release, etcetera. So I'm not sure how those two lines you show could possibly work. There is no kind of substitution to the shadow build directory, or the build type.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              treaves
              wrote on 11 May 2016, 14:45 last edited by
              #6

              I was finally able to get this working. I needed an odd combination of .pri files, and the $$OUT_PWD variable.

              Thanks to all.

              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