Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using a Static Library I Created
Forum Updated to NodeBB v4.3 + New Features

Using a Static Library I Created

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 4 Posters 5.9k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #7
    INCLUDEPATH += D:/MyLibraries/
    LIBS += -LD:/MyLibraries/ -lMy3DLib
    

    The backslash is a line breaker. There's no reason to put it within statements.

    INCLUDEPATH += \ 
            D:/MyLibraries/
    LIBS += \
            -LD:/MyLibraries/ \
            -lMy3DLib
    

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    O 1 Reply Last reply
    1
    • O Offline
      O Offline
      ofmrew
      wrote on last edited by
      #8

      Ignore that last post I tried copying from the Qt documentation and got that mess. It stated that the -L and -l was for Unix only that you should use the full path for Windows. In my case that is d:\MyLibraries\libMy3DLib.a. It does not work when I try
      LIBS =+ d:\MyLibraries\libMy3DLib.a

      Do I need :
      INCLUDEPATH += d:/MyLibraries/libMy3DLib.

      Can I delete that previous reply?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #9

        The INCLUDEPATH variable is to add paths for the compiler to find additional includes. It has no role with regard to the linker.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        O 1 Reply Last reply
        0
        • SGaistS SGaist
          INCLUDEPATH += D:/MyLibraries/
          LIBS += -LD:/MyLibraries/ -lMy3DLib
          

          The backslash is a line breaker. There's no reason to put it within statements.

          INCLUDEPATH += \ 
                  D:/MyLibraries/
          LIBS += \
                  -LD:/MyLibraries/ \
                  -lMy3DLib
          
          O Offline
          O Offline
          ofmrew
          wrote on last edited by
          #10

          @SGaist That does not work. What are we missing?

          1 Reply Last reply
          0
          • SGaistS SGaist

            The INCLUDEPATH variable is to add paths for the compiler to find additional includes. It has no role with regard to the linker.

            O Offline
            O Offline
            ofmrew
            wrote on last edited by
            #11

            @SGaist Normally it would not be needed unless I used some library. But in this case it is needed because of the libMy3dLib and LIBS is also required.

            There were no issues when I created the libMy3DLib but could it be bad?

            1 Reply Last reply
            0
            • O Offline
              O Offline
              ofmrew
              wrote on last edited by
              #12

              I found the following URL
              Same as my problem and another were in the .pro file you right click and get as series of dialogs that allow you to find and select the internal, in the build path can some tell me what that is, or external libraries. I choose external libraries and I finally got the following added to the .pro file:

              QT += core gui

              greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

              CONFIG += c++11

              You can make your code fail to compile if it uses deprecated APIs.

              In order to do so, uncomment the following line.

              #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

              SOURCES +=
              main.cpp
              mainwindow.cpp

              HEADERS +=
              mainwindow.h

              FORMS +=
              mainwindow.ui

              INCLUDEPATH +=
              D:/MyLibraries/

              LIBS +=

              Default rules for deployment.

              qnx: target.path = /tmp/$${TARGET}/bin
              else: unix:!android: target.path = /opt/$${TARGET}/bin
              !isEmpty(target.path): INSTALLS += target

              win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
              else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibd

              INCLUDEPATH += $$PWD/../MyLibraries
              DEPENDPATH += $$PWD/../MyLibraries

              win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLib.a
              else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLibd.a
              else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLib.lib
              else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLibd.lib

              win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
              else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibd

              INCLUDEPATH += $$PWD/../MyLibraries
              DEPENDPATH += $$PWD/../MyLibrariesons/1361229/using-a-static-library-in-qt-creator

              That did not work , so I added

              LIBS +=
              -LD:/MyLibraries/
              -llibMy3DLib

              But it still does not work. What am I missing?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #13

                Where exactly is that library located in your computer ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                O 1 Reply Last reply
                0
                • SGaistS SGaist

                  Where exactly is that library located in your computer ?

                  O Offline
                  O Offline
                  ofmrew
                  wrote on last edited by
                  #14

                  @SGaist The library is located at d:/qtprograms/mylibriaries/ and the library I created is libM3DLib.a. Also what is the build path?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #15

                    Then why did you not use "d:/qtprograms/mylibriaries/" in your .pro file the whole time ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    O 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Then why did you not use "d:/qtprograms/mylibriaries/" in your .pro file the whole time ?

                      O Offline
                      O Offline
                      ofmrew
                      wrote on last edited by
                      #16

                      @SGaist
                      INCLUDEPATH +=
                      D:/qtprograms/MyLibraries/

                      LIBS += -LD:/qtprograms/MyLibraries -llibMy3DLib

                      I originally had the library at d:/MyLibraries but when I saw in the documentation that it should be under the same folder as the program I made the change.

                      If the above ,pro entries are not correct the what should they be?

                      JonBJ 1 Reply Last reply
                      0
                      • O Offline
                        O Offline
                        ofmrew
                        wrote on last edited by
                        #17

                        I forget to give you the details of my computer configuration:
                        {noformat}
                        Qt 6.2.2 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2019) on "windows"
                        OS: Windows 11 Version 2009 [winnt version 10.0.22000]

                        Architecture: x86_64; features: SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 AVX AVX2

                        Environment:

                        Features: QT_NO_EXCEPTIONS

                        Please note that it is Window 11 which I saw might have some plugin issues.

                        I hope this helps because using libraries would seem a must have for application development.

                        1 Reply Last reply
                        0
                        • O ofmrew

                          @SGaist
                          INCLUDEPATH +=
                          D:/qtprograms/MyLibraries/

                          LIBS += -LD:/qtprograms/MyLibraries -llibMy3DLib

                          I originally had the library at d:/MyLibraries but when I saw in the documentation that it should be under the same folder as the program I made the change.

                          If the above ,pro entries are not correct the what should they be?

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #18

                          @ofmrew said in Using a Static Library I Created:

                          INCLUDEPATH += 
                          D:/qtprograms/MyLibraries/
                          

                          Is this really what you have, as shown on two lines?

                          And similarly

                          LIBS +=
                          -LD:/MyLibraries/
                          -llibMy3DLib
                          

                          ?

                          O 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @ofmrew said in Using a Static Library I Created:

                            INCLUDEPATH += 
                            D:/qtprograms/MyLibraries/
                            

                            Is this really what you have, as shown on two lines?

                            And similarly

                            LIBS +=
                            -LD:/MyLibraries/
                            -llibMy3DLib
                            

                            ?

                            O Offline
                            O Offline
                            ofmrew
                            wrote on last edited by
                            #19

                            @JonB The .pro file is:

                            QT += core gui

                            greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

                            CONFIG += c++11

                            You can make your code fail to compile if it uses deprecated APIs.

                            In order to do so, uncomment the following line.

                            #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

                            SOURCES +=
                            main.cpp
                            mainwindow.cpp

                            HEADERS +=
                            mainwindow.h

                            FORMS +=
                            mainwindow.ui

                            INCLUDEPATH +=
                            D:/qtprograms/MyLibraries/libMy3DLib

                            LIBS += -LD:/qtprograms/MyLibraries -lMy3DLib

                            Default rules for deployment.

                            qnx: target.path = /tmp/$${TARGET}/bin
                            else: unix:!android: target.path = /opt/$${TARGET}/bin
                            !isEmpty(target.path): INSTALLS += target

                            win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
                            else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibd

                            INCLUDEPATH += $$PWD/../MyLibraries
                            DEPENDPATH += $$PWD/../MyLibraries

                            win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLib.a
                            else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLibd.a
                            else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLib.lib
                            else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLibd.lib

                            win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
                            else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibd

                            INCLUDEPATH += $$PWD/../MyLibraries
                            DEPENDPATH += $$PWD/../MyLibraries

                            I think that I have tried ever combination for LIBS and INCLUDEPATH, but every time I compile I have not issues, but when I look at mainwindow.cpp i have all my includes marked as file not found.

                            #include "mainwindow.h"
                            #include "ui_mainwindow.h"
                            #include "vector4.h"
                            #include "matrix4x4.h"
                            #include "freefun.h"

                            MainWindow::MainWindow(QWidget *parent)
                            : QMainWindow(parent)
                            , ui(new Ui::MainWindow)
                            {
                            ui->setupUi(this);
                            }

                            MainWindow::~MainWindow()
                            {
                            delete ui;
                            }
                            From what I have found on the Internet I am not the only one having trouble accessing a library on the windows platform. Could win11 be the problem?

                            O 1 Reply Last reply
                            0
                            • O ofmrew

                              @JonB The .pro file is:

                              QT += core gui

                              greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

                              CONFIG += c++11

                              You can make your code fail to compile if it uses deprecated APIs.

                              In order to do so, uncomment the following line.

                              #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

                              SOURCES +=
                              main.cpp
                              mainwindow.cpp

                              HEADERS +=
                              mainwindow.h

                              FORMS +=
                              mainwindow.ui

                              INCLUDEPATH +=
                              D:/qtprograms/MyLibraries/libMy3DLib

                              LIBS += -LD:/qtprograms/MyLibraries -lMy3DLib

                              Default rules for deployment.

                              qnx: target.path = /tmp/$${TARGET}/bin
                              else: unix:!android: target.path = /opt/$${TARGET}/bin
                              !isEmpty(target.path): INSTALLS += target

                              win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
                              else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibd

                              INCLUDEPATH += $$PWD/../MyLibraries
                              DEPENDPATH += $$PWD/../MyLibraries

                              win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLib.a
                              else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/libMy3DLibd.a
                              else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLib.lib
                              else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyLibraries/My3DLibd.lib

                              win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
                              else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibd

                              INCLUDEPATH += $$PWD/../MyLibraries
                              DEPENDPATH += $$PWD/../MyLibraries

                              I think that I have tried ever combination for LIBS and INCLUDEPATH, but every time I compile I have not issues, but when I look at mainwindow.cpp i have all my includes marked as file not found.

                              #include "mainwindow.h"
                              #include "ui_mainwindow.h"
                              #include "vector4.h"
                              #include "matrix4x4.h"
                              #include "freefun.h"

                              MainWindow::MainWindow(QWidget *parent)
                              : QMainWindow(parent)
                              , ui(new Ui::MainWindow)
                              {
                              ui->setupUi(this);
                              }

                              MainWindow::~MainWindow()
                              {
                              delete ui;
                              }
                              From what I have found on the Internet I am not the only one having trouble accessing a library on the windows platform. Could win11 be the problem?

                              O Offline
                              O Offline
                              ofmrew
                              wrote on last edited by
                              #20

                              @ofmrew Since the include statement has the error file not found is it looking for a file and not an entry in the library?

                              jsulmJ 1 Reply Last reply
                              0
                              • O Offline
                                O Offline
                                ofmrew
                                wrote on last edited by
                                #21

                                I believe that I start from the beginning by creating a new library and then try to use it.

                                1 Reply Last reply
                                0
                                • O ofmrew

                                  @ofmrew Since the include statement has the error file not found is it looking for a file and not an entry in the library?

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #22

                                  @ofmrew said in Using a Static Library I Created:

                                  Since the include statement has the error file not found is it looking for a file and not an entry in the library?

                                  Include files are not entries in libraries. If your header file is not found then check whether your added correct include folder in INCLUDEPATH

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  O 1 Reply Last reply
                                  0
                                  • jsulmJ jsulm

                                    @ofmrew said in Using a Static Library I Created:

                                    Since the include statement has the error file not found is it looking for a file and not an entry in the library?

                                    Include files are not entries in libraries. If your header file is not found then check whether your added correct include folder in INCLUDEPATH

                                    O Offline
                                    O Offline
                                    ofmrew
                                    wrote on last edited by
                                    #23

                                    @jsulm As I understand it, the .h files in the library I created are in a list of (I am not sure of the exact term) items in the library. I assume also that the compiler will look first at the header files in the project and then in libraries. If that is correct then either the library could not be found or the library does not include the header. If I could print the contents of the library then I could answer that question. It seem straight forward in Linux, but not Win.

                                    Also I would like to point out that the Qt documentation is inconsistent, in one place it shows the full Win path, starting with the drive letter for windows and the -L and -l for the path and the library, respectively. It would seem that there are few problems encountered by Linux users, but that is not the case for Win users. Nearly all of the examples are for Linux, not windows. If there was only one example that was win based, complete and that worked, then I could validate it on my system, I could then make some progress. Is CMAKE the solution, not QMAKE? Someone have a cmake example the meets the above criteria?

                                    jsulmJ 2 Replies Last reply
                                    0
                                    • O ofmrew

                                      @jsulm As I understand it, the .h files in the library I created are in a list of (I am not sure of the exact term) items in the library. I assume also that the compiler will look first at the header files in the project and then in libraries. If that is correct then either the library could not be found or the library does not include the header. If I could print the contents of the library then I could answer that question. It seem straight forward in Linux, but not Win.

                                      Also I would like to point out that the Qt documentation is inconsistent, in one place it shows the full Win path, starting with the drive letter for windows and the -L and -l for the path and the library, respectively. It would seem that there are few problems encountered by Linux users, but that is not the case for Win users. Nearly all of the examples are for Linux, not windows. If there was only one example that was win based, complete and that worked, then I could validate it on my system, I could then make some progress. Is CMAKE the solution, not QMAKE? Someone have a cmake example the meets the above criteria?

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #24

                                      @ofmrew said in Using a Static Library I Created:

                                      As I understand it, the .h files in the library I created are in a list of (I am not sure of the exact term) items in the library

                                      Don't know what you mean. Header files are not entries in a library. They are text files which can be located in any location - that is why you need to tell the compiler where to find them using INCLUDEPATH. There is really not much to say, simply set INCLUDEPATH properly...

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      0
                                      • O ofmrew

                                        @jsulm As I understand it, the .h files in the library I created are in a list of (I am not sure of the exact term) items in the library. I assume also that the compiler will look first at the header files in the project and then in libraries. If that is correct then either the library could not be found or the library does not include the header. If I could print the contents of the library then I could answer that question. It seem straight forward in Linux, but not Win.

                                        Also I would like to point out that the Qt documentation is inconsistent, in one place it shows the full Win path, starting with the drive letter for windows and the -L and -l for the path and the library, respectively. It would seem that there are few problems encountered by Linux users, but that is not the case for Win users. Nearly all of the examples are for Linux, not windows. If there was only one example that was win based, complete and that worked, then I could validate it on my system, I could then make some progress. Is CMAKE the solution, not QMAKE? Someone have a cmake example the meets the above criteria?

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #25

                                        @ofmrew said in Using a Static Library I Created:

                                        in one place it shows the full Win path, starting with the drive letter for windows and the -L and -l for the path and the library

                                        Yes, because linking works differently on Windows...

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        O 1 Reply Last reply
                                        0
                                        • jsulmJ jsulm

                                          @ofmrew said in Using a Static Library I Created:

                                          in one place it shows the full Win path, starting with the drive letter for windows and the -L and -l for the path and the library

                                          Yes, because linking works differently on Windows...

                                          O Offline
                                          O Offline
                                          ofmrew
                                          wrote on last edited by
                                          #26

                                          @jsulm The library path in Win11 is D:\QtPrograms\MyLibraries\libMy3DLib.a

                                          When I use
                                          INCLUDEPATH +=
                                          -LD:/qtprograms/MyLibraries/

                                          LIBS += -lMy3DLib
                                          I get
                                          :-1: error: No rule to make target 'D:/qtprograms/TestMy3DLib/../MyLibraries/libMy3DLibd.a', needed by 'debug/TestMy3DLib.exe'. Stop.
                                          I remember seeing another entry for debug in some post any idea?

                                          jsulmJ 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