Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Right way to create a library (QTProject) and use this in another project
Forum Updated to NodeBB v4.3 + New Features

Right way to create a library (QTProject) and use this in another project

Scheduled Pinned Locked Moved Mobile and Embedded
libraryreferenceqtcreator
6 Posts 2 Posters 2.1k 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.
  • G Offline
    G Offline
    GustavoCaldeira
    wrote on last edited by
    #1

    Hi!

    How is the right way to create a library project and reference this project in other projects in QT.

    I did a reference using INCLUDEPATH but I'm getting 'undefined reference' error on the objects.

    Thanks

    U 1 Reply Last reply
    0
    • G GustavoCaldeira

      Hi!

      How is the right way to create a library project and reference this project in other projects in QT.

      I did a reference using INCLUDEPATH but I'm getting 'undefined reference' error on the objects.

      Thanks

      U Offline
      U Offline
      ucmar
      wrote on last edited by ucmar
      #2

      hi @GustavoCaldeira, have you tried adding:

      LIBS += -L"libpath" -llibname

      (pay attention to the naming convention of the library file - it must begin with prefix "lib")
      (also, the double "l" in the last parameter is not a typo, but it comes from the parameter starting with "-l")

      in your .pro file?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GustavoCaldeira
        wrote on last edited by GustavoCaldeira
        #3

        @ucmar thanks by the reply!

        Well, I inserted this way:

        LIBS += -L"../infinity-commons" -llibInfinityCommons

        ../infinity-commons is the folder of the other project...

        and now, how do I use a class that is inside the library? I included the .h file but it was not found...

        U 1 Reply Last reply
        0
        • G GustavoCaldeira

          @ucmar thanks by the reply!

          Well, I inserted this way:

          LIBS += -L"../infinity-commons" -llibInfinityCommons

          ../infinity-commons is the folder of the other project...

          and now, how do I use a class that is inside the library? I included the .h file but it was not found...

          U Offline
          U Offline
          ucmar
          wrote on last edited by
          #4

          @GustavoCaldeira regarding lib file convention, you should rather be writing

          LIBS += -L"../infinity-commons" -lInfinityCommons

          and your file should be named libInfinityCommons.dll
          (in practice, you have to omit the prefix "lib" in the .pro file, but the file name must have it)

          If your class header is not found it means there is some problem with your INCLUDEPATH. Try using an absolute path first (i.e. C:...) and then, if the header is found, try to change it to a relative path.

          If the header gets found, while you are typing the #include directive the autocompletion will list your header filename.

          Another hint: consider that the path in the LIBS += ... directive must point to the folder where the binary library file is located, which, in general, is not the same folder as the library project source files folder! For example, you can have a shadow-build directory located elsewhere...

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

            Thanks @ucmar

            This worked for me... my .pro is now like this:

            LIBS += -L"/myhome/build-folder/infinity-commons" -lInfinityCommons
            INCLUDEPATH += ../infinity-commons

            U 1 Reply Last reply
            0
            • G GustavoCaldeira

              Thanks @ucmar

              This worked for me... my .pro is now like this:

              LIBS += -L"/myhome/build-folder/infinity-commons" -lInfinityCommons
              INCLUDEPATH += ../infinity-commons

              U Offline
              U Offline
              ucmar
              wrote on last edited by
              #6

              @GustavoCaldeira you are welcome, glad it worked. Could you please mark the thread as solved? Thanks!

              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