How to use third-party libraries in Qt 6.3.2 - c++

I wanted to use a library in my Qt project which it has three files: One header file (.h file), One static file (.lib), and finally a Dll file which I have to use it along my executable.
I added .h file content to my project but I should introduce .lib file to the Qt linker. I use the following comment for the linker in configuration file:
LIBS += Path to lib file
But it frequently gives me the following error:
Parse error. Expected "(", got unquoted argument with text "+=".
Then I try the following one again:
LIBS += "Path"
It gives me the above error again, I used the following code too:
LIBS += ("Path")
But it is not work again. However, How can I introduce .lib file to the linker in Qt 6.3.2?
Thank you.

Related

Boost libraries static linking

I've made a static library project which is using some boost libraries in its work. I've hidden all signs of boost from my static library header files as well.
Now I'm trying to create test console app with my library. I've set up include and lib paths to my library directories and got an "fatal error LNK1104: cannot open file 'libboost_filesystem-vc142-mt-gd-x64-1_76.lib'".
If I include path to .lib files of boost it works, but I wish not to do that in order to not have any dependencies for my library using. Can I achieve that?
Also I've tried to create composite lib file as described here with command "lib /out:composite.lib Client.lib libboost_filesystem-vc142-mt-gd-x64-1_76.lib" and rename composite.lib as Client.lib. I've got bunch of warnings LNK4006 (already defined in Client.lib ... second definition ignored). Result has appropriate size as sum of initial libraries sizes, but still doesn't work.

How do I go about adding a third party library to QtCreator?

I'm trying to add OpenXLSX to my QtCreator project but following this guide I can't seem to get QtCreator to find the header file.
The QtCreator manual mentions .lib files which this library doesn't use so I'm kinda lost with that guide. I googled around and tried adding all the headers and sources from OpenXLSX/#library/#openxlsx/interfaces/c++/ to my headers and sources directories in the project tree. Yet I still get
exceltest.cpp:3: error: 'OpenXLSX.h' file not found
Line 3 is
#include "OpenXLSX.h"
I've also tried
#include "3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/OpenXLSX.h"
The 3rdparty directory being in the same location as exceltest.pro
I've also tried both with angle brackets.
I don't need any advanced functionality from OpenXLSX, just reading and writing values to cells I specify to either .xlsx or .xls.
I'm also not married to the idea of using OpenXLSX so if anyone knows excel any libraries that would work better I'm open to the idea.
EDIT: So after I added my headers and sources to the project tree, my exceltest.pro looks like this.
I tried putting this line
#include "3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/OpenXLSX.h"
into exceltest.h instead of exceltest.cpp and I'm getting different errors. QtCreator seems to find the library files but is something wrong with the library? These are the errors:
In file included from J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/XLCell.h:49:0,
from ..\exceltest\3rdparty\OpenXLSX\#library\#openxlsx\interfaces\c++\sources\XLCell.cpp:5:
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/XLDefinitions.h:57:35: warning: multi-character character constant [-Wmultichar]
constexpr uint32_t maxRows = 1'048'576;
^~~~~
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/XLDefinitions.h:59:36: warning: missing terminating ' character
constexpr uint16_t maxCols = 16'384;
^
J:/George/Coding/Qt/Test/exceltest/3rdparty/OpenXLSX/#library/#openxlsx/interfaces/c++/headers/XLDefinitions.h:59:36: error: missing terminating ' character
constexpr uint16_t maxCols = 16'384;
^~~~~
..\exceltest\3rdparty\OpenXLSX\#library\#openxlsx\interfaces\c++\sources\XLCellRange.cpp:5:10: fatal error: XLCellRange.h: No such file or directory
#include <XLCellRange.h>
^~~~~~~~~~~~~~~
compilation terminated.
..\exceltest\3rdparty\OpenXLSX\#library\#openxlsx\interfaces\c++\sources\XLCellReference.cpp:5:10: fatal error: XLCellReference.h: No such file or directory
#include <XLCellReference.h>
^~~~~~~~~~~~~~~~~~~
First, you have to build the OpenXLSX project to get the library. The project uses cmake for generation. You need to generate the worksapce, first:
List all the available generators with
cmake --help
Chose the one you want to use, then:
cmake . -G "Your generator"
Build your project according to your generator. The libraries and headers will be copied in the install directory.
In your .pro file, add the following lines:
INCLUDEPATH += /path/to/OpenXLSX/include
LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.lib
The first one allows you to include the OpenXLXS headers. The second line will be used by the linker to link the library to your app.
You may need to use a different version of your library if you want to build your project on Windows or Linux. You can use this syntax:
# On Windows in release mode
win32:CONFIG(release, debug|release): LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.dll
#On Windows debug mode
else:win32:CONFIG(debug, debug|release): LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx_debug.dll
#On Linux debug and release
else:unix: LIBS += -L/path/to/OpenXLSX/lib -lopenxlsx.so
In Qt Creator, if you right-click on your project, you can use the dedicated wizard to add a library (Add Library option in the context menu). It will add everything you need in your *.pro

QtRPT : cannot find -lQtZint

I have problem including QTRPT in my project.
I've copied all files and folders from "QtRptProject 1.5.2/QtRptProject" folder to my project folder (where .pro & .cpp & .h files are) and I've also inserted the line "include(QtRPT/QtRPT.pri)" in my .pro file (at the end).
The problem is that when compiling I get this error :
-1: error: cannot find -lQtZint
How can I fix it.
Thank you
If you are going to use a barcode feature, you need copy also zint-2.4.4 folder. Before building your project, you should build zint library first. Probably you problem in paths

ATL linker error: Cannot open input file ***.obj

I am trying to use the ATL library in my program. I am using Qt 5.2.
After adding the header files path to the Qt .pro file:
INCLUDEPATH += "C:/WinDDK/7600.16385.1/inc/at171/"
the first error was:
LNK1104: cannot open file 'atls.lib'
This was solved by adding path to the atls.lib:
LIBS += "C:/WinDDK/7600.16385.1/lib/ATL/i386/"
Now I get the error:
LNK1181: cannot open input file 'C:/WinDDK/7600.16385.1/lib/ATL/i386/.obj'
There are no object files in this folder, but why does it look for one when it requested the atls.lib?
I need some help to solve this problem.
I'm not sure exactly how your Makefile is setup, but LIBS is generally reserved to be a list of .a, .so, or .lib files. You would want to set LIBPATH to specify what directory to search for all the libraries in LIBS
INCLUDEPATH += "C:/WinDDK/7600.16385.1/inc/at171/"
LIB += "atls.lib" # shouldn't be needed: it's already looking for atls.lib.
LIBPATH += "C:/WinDDK/7600.16385.1/lib/ATL/i386/"

Why is Qt recognizing neither my header files, nor my library files?

The above is my PRO file. There is a PvAPI.lib, an ImageLib.lib, and a PvApi.h, an ImageLib.h file, and a StdAfx.h file. The latter three are in the INCLUDEPATH paths and the library locations are given as follows under LIBS.
However, the compiler still doesn't seem to recognize the first header file that's brought up. Any reason as to why? Perhaps I am declaring the paths incorrectly?
Issues:
C:\Users\Andrew\Desktop\GO TO
HELL\HardTrigger\USERINTERFACE-THINGS\UserInterface-build-desktop-Qt_4_8_1_for_Desktop_-_MSVC2010__Qt_SDK__Debug....\HardTrigger.cpp:62: error: C1083: Cannot open include file: 'PvApi.h': No such file or
directory
PvApi.h seems to be in "somefolder\inc-pc", while INCLUDEPATH contains "somefolder\inc-pc\include"