Using a Static Library I Created
-
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.cppHEADERS +=
mainwindow.hFORMS +=
mainwindow.uiINCLUDEPATH +=
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 += targetwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrarieswin32-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.libwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrariesons/1361229/using-a-static-library-in-qt-creatorThat did not work , so I added
LIBS +=
-LD:/MyLibraries/
-llibMy3DLibBut it still does not work. What am I missing?
-
Where exactly is that library located in your computer ?
-
Then why did you not use "d:/qtprograms/mylibriaries/" in your .pro file the whole time ?
-
@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?
-
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.
-
@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?
-
@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
?
@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.cppHEADERS +=
mainwindow.hFORMS +=
mainwindow.uiINCLUDEPATH +=
D:/qtprograms/MyLibraries/libMy3DLibLIBS += -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 += targetwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrarieswin32-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.libwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrariesI 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? -
@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.cppHEADERS +=
mainwindow.hFORMS +=
mainwindow.uiINCLUDEPATH +=
D:/qtprograms/MyLibraries/libMy3DLibLIBS += -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 += targetwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrarieswin32-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.libwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyLibraries/ -lMy3DLibdINCLUDEPATH += $$PWD/../MyLibraries
DEPENDPATH += $$PWD/../MyLibrariesI 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? -
@ofmrew Since the include statement has the error file not found is it looking for a file and not an entry in the library?
@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
-
@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
@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?
-
@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?
@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...
-
@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?
@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...
-
@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...
@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? -
@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?@ofmrew said in Using a Static Library I Created:
INCLUDEPATH +=
-LD:/qtprograms/MyLibraries/What is this?!
INCLUDEPATH contains the folders where include headers are located and has nothing to do with library files (.so, .dll, .lib, .a).
-L defines the path where libraries are located. -l defines library file name.
So, it should be like:INCLUDEPATH += PAT_TO_HEADER_FILE_FOLDER LIBS += -lD:/qtprograms/MyLibraries/libMy3DLib.a