Adding libraries to project - c++

I'm new to Qt, and got following error to my C++ project:
fatal error: apr_pools.h: No such file or directory
I installed apr from https://apr.apache.org/compiling_unix.html and compiled it by executing:
./configure
make
make install
But I have no idea now how to link proper files to my project.

I solved my problem by adding external library. The result in .pro file is as below:
unix:!macx: LIBS += -L/usr/local/apr/lib/ -lapr-1
INCLUDEPATH += /usr/local/apr/include/apr-1
DEPENDPATH += /usr/local/apr/include/apr-1
But anyway thanks everyone for their time and good intentions :)

You must:
Specity in your .pro where header files must be searched: something like win32:INCLUDEPATH += "C:/mylibs/extra headers"
unix:INCLUDEPATH += "/home/user/extra headers"
You must specify which library must to be linked: something like
win32:LIBS += /mylibs/lib.so
unix:LIBS += c:/mylibs/library

This is not about linking but about preprocessing for now. (the preprocessor = the program or part of the compiler which read all the lines beginning with a '#' and replace macro and insert included headers.)
The preprocessor can't find your header
see http://qt-project.org/doc/qt-5/qmake-project-files.html#declaring-other-libraries
you have to add an include path to where your additional headers are.
[EDIT]
But there are no packages in your distribution ?
What is you OS, or linux distribution ?
if you want to install the bins and headers, maybe something like ./configure --prefix=/usr ; sudo make install should be needed or copy the files directly (adapt to your system and for the makefile)
[/EDIT]

Related

How to add the built from source boost library to qt creator on linux

I compiled the boost library from the source using the scripts that came with the source (below the commands that I wrote)
/bootstrap.sh —prefix=/libs
./b2 install
After the build, 2 new directories appeared in the libs directory, include and lib, respectively.
Next, I registered the path to boost in the pro file qt creator
TEMPLATE = app
CONFIG += console c++17
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
INCLUDEPATH += I-/libs/include/boost
LIBS += -L/libs/lib
In theory, I specified the path to both the headers (include / boost) and the binaries (lib), but nevertheless, when I try to compile the test code, I get a bunch of errors. How to correctly register a pro file if I want to connect asio, on Linux, where did I go wrong? (set of errors)
You are not giving the library name in LIBS, only giving the path. Correct format is:
LIBS += -L<pathToLibrary> -l<libraryName>
Moreover INCLUDEPATH syntax is also incorrect. There's no need for I-.
INCLUDEPATH += /path/to/library
# e.g
INCLUDEPATH += libs/include/boost
And btw you don't need to link to anything if you are using asio only, since as far as I remember, Asio is header only so only include path will be necessary.

QtCreator unable to find Qxt headers on Linux?

I'm working on a Qt5/QtQuick/QML application that's supposed to use QxtGlobalShortcut for hotkey control when the application is hidden or out of focus. I've been developing it using QtCreator on Linux, and I'm not entirely familiar with Linux development so I may have missed something simple.
First off, I tried cloning the master branch of the Qxt git repo from here. But for some reason ./configure failed to create a makefile according to an error that I was getting from make and make install. I'm not very experienced in building other people's projects/libraries from source, and the output I was getting from ./configure wasn't specific enough for me to figure out what was going on..
So instead, I decided to grab libqxt-dev from (X)ubuntu's APT repo. After it finished installing I added these lines to the bottom of my QtCreator project file:
INCLUDEPATH = usr/include
CONFIG += qxt
QXT += core gui
After setting up a basic global shortcut based totally off the Qxt documentation's example. I got a few compilation errors. First of all, the Qxt seem to use:
#include <QxtGlobalShortcut>
But QtCreator couldn't find that file, so I changed it to this:
#include <qxt/QxtGui/QxtGlobalShortcut>
Now it could find the Global Shortcut class header, and QtCreator stopped grumbling at me. Unfortunately, upon compilation QtCreator shot out this error message:
/usr/include/qxt/QxtGui/qxtglobalshortcut.h:28: error: qxtglobal.h: No such file or directory
I think this is caused by a problem in my project's INCLUDE path or something, but even having tried changing my projects INCLUDE path to this:
INCLUDEPATH = usr/include
usr/include/qxt/QxtCore
usr/include/qxt/QxtGui
CONFIG += qxt
QXT += core gui
I still get the same error message that QxtGlobal.h (which is being #included in QxtGlobalShortcut.h) can't be found..
So, I'm really not sure what I've done wrong, and I'm out of ideas about how to fix this.
Hopefully someone can help me understand what step I've skipped so that I can continue coding! Thanks!
EDIT: Here's what I have for my entire Qt project .pro file:
TEMPLATE = app
QT += qml quick
SOURCES += main.cpp \
Gamepad.cpp \
Script.cpp \
System.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
HEADERS += \
Gamepad.h \
Script.h \
System.h
LIBS += -L/usr/lib -lSDL2
CONFIG += qxt
QXT += core gui
Everything before LIBS was automatically generated by QtCreator for my project. I added the LIBS, CONFIG, and QXT elements as per the user instructions for SDL2 and Qxt.
This is a big problem here:
INCLUDEPATH = usr/include
1) You are using relative path from the current working directory, so not /usr/include from the root of the filesystem.
2) You are deleting everything in the INCLUDEPATH because you set rather than append with +=.
3) It is unnecessary to add that line anyway since /usr/include will be looked up by default.
4) Even if it was not, you have #include "qxtglobal.h" instead of #include <qxtglobal.h>.
I would suggest to delete that line and then it should just work.

Qt .pro file: adding path which includes "include" directory doesn't work

I am including new files in my Qt project. The header files are installed by another application in a path like this:
INCLUDEPATH += <path>\\include
The problem is that Qt recognizes the include as a reserved word, and does not recognizes the header files in this folder. When I rename the folder to Include or include2 - everything works well, the files of this folder are imported successfully.
I do not want to change the folder name because every other user that will want to compile my application will have to do this too. Can anyone please suggest me other solution?
Thanks!
Had the same problem.
Just add $$quote, and put the path in braces.
For example:
$$quote(C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\include)
use
INCPATH = -I/<path>/include
or specify each file explicitly
HEADERS = include/menuinterface.h \
include/editormenuinterface.h \
include/schematicmenuint
...
Try using / as separator symbol:
INCLUDEPATH += "<path>/include"

how to add zlib to an existing qt installation

How can I add zlib to an existing installation of Qt. I m pretty new in this so please give me detailed description!
Thanks for your help in advance!
zlib is contained in the core Qt libraries. If you want to use the zlib functions in a Qt program, you only have to include zlib.h which is in src/3rdparty/zlib. See e.g. the implementation of QByteArray in src/corelib/tools.
If you want to use quazip, just add the library to your project. It is based on the Qt libraries. Take care to build the correct qyazip library that corresponds to your Qt installation.
You get the correct include path by adding the following line to your project file:
INCLUDEPATH += $$[QT_INSTALL_PREFIX]/src/3rdparty/zlib
For Qt5, see Thorbjørn's comment: it is sufficient to use #include <QtZlib/zlib.h>.
The current answer is only valid for Qt4. Since Qt5 the zlib header file is stored in a different directory. Using the qmake property QT_INSTALL_HEADERS you can add to your .pro file:
INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtZlib
This works e.g. to build quazip, if you add it to quazip.pro
The property $$[QT_INSTALL_HEADERS] points to QTDIR/qtbase/include/ within which lies QtZlib/zlib.h.
Without changing the includepath you have to change every include-statement to #include <QtZlib/zlib.h> as commented by Thorbjørn.
If you want to use zlib for compression/uncompression, use qCompress/qUncompress.
At least some people here want to build Quazip, which requires zlib.
Here's how I did it on windows with quazip 0.4.3.
First in the quazip.pro I changed SUBDIRS to contain only:
SUBDIRS=quazip
Then I downloaded zlib binaries and source from:
http://www.winimage.com/zLibDll/zlib125dll.zip [binaries]
http://www.winimage.com/zLibDll/zlib125.zip [source]
both links came from http://zlib.net
Then in the subfolder quazip/quazip.pro I added:
INCLUDEPATH += <path to zlib source>
in the win32 {} section I commented this line:
# *-msvc*: QMAKE_LFLAGS += /IMPLIB:$$DESTDIR\\quazip.lib
and I modified the LIBS line to this:
*-msvc*: LIBS += -lzlibwapi -L<path to zlib binaries>/dll32
I also modified in zip.c and unzip.c the
#include "zlib.h"
to become:
#include <zlib.h>
After that I build this to Release mode and got a DLL out.
Then in the project to use this, I added the following config:
INCLUDEPATH += <quazip source path>
INCLUDEPATH += <zlib source path>
LIBS += -L<quazip source path>\quazip\release -lquazip
And that builds and works, but only in Release mode for the test app. In Debug mode i get assertion errors and it fails.

How do a specify a library file dependency for qmake in Qt?

Have a SomeLib.pro file that contains:
CONFIG += debug
TEMPLATE = lib
TARGET = SomeLib
..
Then in a dependent SomeApp.pro:
..
debug:LIBS += -lSomeLib_debug
..
How can I force SomeApp to build if I touched SomeLib in qmake?
It's ugly because you need to give the exact library file name, but this should work:
TARGETDEPS += libfoo.a
QT Creator will do the work if you click "Add library..." in the context menu of the project that should include the library.
These variables are configured automatically for you:
LIBS
INCLUDEPATH
DEPENDPATH
PRE_TARGETDEPS
See also http://doc.qt.digia.com/qtcreator-2.1/creator-project-qmake-libraries.html
In reply to Zahir's comment, it's perhaps worth pointing out that stating this dependency in qmake files is unnecessary if using DLLs, but is essential if your exe depends on a static library.
qmake does not provide this ability.
Instead, put your app and lib in subdirectories, then create a Makefile in their parent directory that looks something like this:
all: FRC
cd Somelib && qmake && $(MAKE)
cd SomeApp && qmake && $(MAKE)
FRC:
Then always run make from this directory.
I used:
POST_TARGETDEPS += c:/open-en/lib/win32mingw/libosal_based.a
It works, but is clumsy since it is necessary specify full path to library, which is different for every operating system/compiler.
surely that can't be possible, you are talking about using qmake to do a reverse dependency lookup? so what u want is for it to build app B (and any other app dependent on library A) after you've made a change to library A?
that's a bit like saying recompile all visual basic apps if vbrun300.dll is updated?