how to add zlib to an existing qt installation - c++

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.

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.

Build c++ Qt CLI Tool with Quazip

so normally I am an embedded software developer first time I need to do something like that... So I am no expert at all at this... I have come this far with a lot of googling and trial and error methods...
What I want to do
I need to write a C++ CLI application which can zip and unzip files.
Quazip
zlib
My general conditions
I want to use Qt and Quazip since Qt doesn't support zipping natively (or does it).
I want to build with Mingw and CMake for Windows 64bit on a Windows 64bit system.
With my knowledge, it would be best if I compile Quazip statically so I don't depend on any other quazip DLL which may be present on other systems...
How I think It works
I need to compile zlib
Then I need to compile Quazip (with zlib)
Link the compiled libraries to my project.
My research
I found two good youtube videos which should help me:
https://www.youtube.com/watch?v=5ZTusMX-Reo
https://www.youtube.com/watch?v=mxlcKmvMK9Q
No of these ways did work out for me.
Also I found that blog post which was a little bit of help...
http://www.antonioborondo.com/2014/10/22/zipping-and-unzipping-files-with-qt/
This site was available till yesterday now it's gone :D
Also I found that old Stackoverflow question which helped me a bit:
How to connect the QuaZip library in CMake
Detailed steps on what I did:
1. Building zlib
Downloaded the latest version of zlib from the official website. version 1.2.11
I build zlib with the following commands:
cd C:/some/Path/zlib-1.2.11
mingw32-make -f win32/Makefile.gcc
That works perfectly I get a
libz.a
libz.dll.a
zlib1.dll
those files and all the header files (11 files) I copy in a seperate folder. Which looks like this:
Build
|
+-include
+-lib
Headers in the include folder the libs in the lib folder.
2. Building Quazip
Now the messy part...
Downloading the newest version of Quazip (version 0.8.1) from the GitHub.
I tried various ways to compile Quazip. The one I stick to was:
Open the .pro file in Qt creator inside the quazip folder (the folder where the sources are located).
So then I added the compiled zlib to the Qmake file.
Following lines I added at the end of the file:
INCLUDEPATH += "C:/Build/include"
LIBS += -L"C:/Build/lib"
LIBS += -lz
Then build Quazip with QtCreator as release Build.
When compiled I get
quazip.dll
libquazip.a
I copy all the header files from quazip (16 fils) in the include folder and the two libs in the lib folder.
Now I have like a zippackage in the build folder.
3. Adding Quazip and zlib to my Project
Copied the FindQuazip.cmake file into my project form the Quazip Repo.
In my CMakeLists.txt I added the following lines:
set(ZLIB_ROOT "C:/BUILD" CACHE PATH "Path to zlib")
find_package(ZLIB REQUIRED)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(QuaZip REQUIRED)
I need to set the ZLIB_ROOT so CMake uses the zlib I want. If I don't set Root he uses a zlib from a ruby installation from my PC.
Also I added
include_directories(
"${BASE_DIR}/sources"
"${QUAZIP_INCLUDE_DIR}"
)
and at the end
add_executable(${PROJECT_NAME} ${SOURCES} ${INC_ALL} )
target_link_libraries(${PROJECT_NAME} Qt5::Network Qt5::Core Qt5::Widgets
${ZLIB_LIBRARIES}
${QUAZIP_LIBRARIES}
)
Then I needed to add the FindQuazip.cmake since it would find the libs: I edited the following:
FIND_PATH(QUAZIP_LIBRARY_DIR
WIN32_DEBUG_POSTFIX d
NAMES libquazip.a #quazip.dll
HINTS "C:/Build/lib"
PATH_SUFFIXES QuaZip/lib
)
FIND_LIBRARY(QUAZIP_LIBRARIES NAMES libquazip.a HINTS ${QUAZIP_LIBRARY_DIR})
FIND_PATH(QUAZIP_INCLUDE_DIR NAMES quazip.h HINTS ${QUAZIP_LIBRARY_DIR}/../include)
FIND_PATH(QUAZIP_ZLIB_INCLUDE_DIR NAMES zlib.h)
Okay so It took me two days to get to there where I am now.
Now when I run CMake every works fine. He finds the libs.
I can even include a the Header files of Quazip. But when I then try to compile a minimal example the linker can't find any symbols.
Minimal Example:
#include <iostream>
#include <QApplication>
#include "JlCompress.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
cout << __cplusplus << endl;
cout << "Hello World!" << endl;
JlCompress::compressDir("C:/WorkspaceLokal/Test/test.zip", "C:/WorkspaceLokal/Test/TestFolder");
return a.exec();
}
By compiling it I get the following error:
C:\some\path\sources\main.cpp:-1: Fehler: undefined reference to `JlCompress::compressDir(QString, QString, bool)'
This means the linker can't link the function...
My Question
What am I doing wrong?
Do I need to compile Quazip in another way?
Edit 4:
since it now works how to I compile the Quazip as a static lib, so that I can link it statically to my application?
Thanks in advance...
Edit 1:
Here are the QUAZIP variables from Qt creator:
Edit 2:
Okay. Some news. the libquazip.a is something else and doesn't work. If I link against the quazip.dll compiling works. But when I run the application it crashes at the function call compressDir...
Edit 3:
It works. I just needed to copy the quazip.dll to the compiled executable...
From QuaZip's pro file:
# You'll need to define this one manually if using a build system other
# than qmake or using QuaZIP sources directly in your project.
CONFIG(staticlib): DEFINES += QUAZIP_STATIC
This should trigger when you add staticlib to the CONFIG in quazip.pro (2nd line):
CONFIG += qt warn_on staticlib
If you are not using qmake to build Quazip, just make sure that you #define QUAZIP_STATIC in a way specific to your build system

QtCreator for iOS: How to deploy a dylib shared library with my application

I'm having a hard time deploying dynamic shared libraries on iOS.
To isolate and expose the problem, I have a very simple "HelloWorld" project: A library exporting class with a function returning "Hello World" and a program using the class and displaying the message.
I'm using QtCreator with Qt 5.5.
I'm able to generate the .dylib file and link my program. But, when I deploy it on the iPhone, I get the error:
Démarrage des processus distants.
dyld: Library not loaded: libMyLib.1.dylib
Referenced from: /private/var/mobile/Containers/Bundle/Application/D6942CCE-828D-4C10-86DA-F7DA7ADF7449/MyApp.app/MyApp
Reason: image not found
On Android, I had the same kind of issue and could fix it by manually adding the shared library to the final package (apk) file, using ANDROID_EXTRA_LIBS. But I can find no equivalent for iOS.
Here are my .pro files. Full project can be downloaded here. I reported this to Qt as a bug, but if one could propose a kind of workaround this would help!
MyLib.pro:
QT -= core gui
TARGET = MyLib
TEMPLATE = lib
DEFINES += MYLIB_LIBRARY
SOURCES += mylib.cpp
CONFIG += shared
HEADERS += mylib.h\
mylib_global.h
MyApp.pro:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MyApp
TEMPLATE = app
SOURCES += main.cpp\
dialog.cpp
HEADERS += dialog.h
INCLUDEPATH += ../MyLib
LIBS += ../MyLib/libMyLib.dylib
I'd like the solution to be all embedded in QtCreator. The only think that should be changed here is one of the two .pro files. Possibly with post-build calls to MACOS commands...? Or just a post-build instruction in MyApp.pro to copy the dylib in the right place (.app target folder) before application is deployed? I'm really surprised this is not covered silently by QtCreator....
Note: This question suggests to set DYLD_LIBRARY_PATH. But I have no clue hox to do this within the MyApp.pro file nor how it will help upon iOS deployment (as DYLD_LIBRARY_PATH can be set the MAC PATH to the lib, not the iPhone PATH to the lib...)
1) In your library project make sure your dylibs have installname #rpath/mylib.dylib or such. E.g. by adding QMAKE_SONAME_PREFIX = #rpath to your library .pro file.
(You can check by looking at the first line of otool -L /path/to/libmylib.dylib. If the library is a prebuilt 3rdparty one, change it with install_name_tool -id #rpath/libmylib.dylib)
2) add the following to the application .pro file
# link to the lib:
LIBS += -L../mylib -lmylib
# make the app find the libs:
QMAKE_RPATHDIR = #executable_path/Frameworks
# deploy the libs:
mylib.files = $$OUT_PWD/mylib/libmylib.1.dylib
mylib.path = Frameworks
QMAKE_BUNDLE_DATA += mylib
I came up with a workaround for that, in case it could help anyone.
Build your library statically instead of dynamically (replace CONFIG += shared by CONFIG += staticlib
Now, compiler will generate *.a files instead of *.dylib, You must use this extension when linking libraries (replace LIBS += myLib.dylib by LIBS += myLib.a)
If your library was only linked by a program, you are done
If your library, let's call it (A), was used by another library (B), then (B) should not link with it anymore (No LIB flag in B.pro). Only the top level program will link with all your static libraries.
With this approach, I could deploy a program using 15 libraries on an iPhone with QtCreator.

Adding libraries to project

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]

Problem installing QCA-OSSL (part of the Qt Cryptographic Architecture) plugin on Windows 7

I have been trying to use QCA (Link) on my Windows PC for a couple of days now, works fine on my linux box, just can't get it working with Windows.
So i followed all the instructions for installing QCA and then the ossl plugin for QCA. The QCA works fine but for some reason the plugin isn't showing up in my Qt Creator nor am I able to use some of the functions in the plugin.
I used the qcatool2.exe that comes with QCA to check my plugins using
qcatool2 plugins --debug
and get this error message:
plugin: qca-ossl2.dll: failed to load: The plugin 'C:/Qt/2010.05/qt/plugins/crypto/qca-ossl2.dll' uses incompatible Qt library. Expected build key "Windows mingw debug full-config", got "Windows mingw release full-config"
Now this seems to me as if qt requires the plugin to be compiled in debug mode (as to get the build key to contain debug rather than release) so I added
CONFIG += debug
to my plugin's project file and ran qmake and mingw32-make as usual but this seems to have had no effect.
My project file for the plugin is now:
TEMPLATE = lib
CONFIG += plugin
QT -= gui
DESTDIR = lib
VERSION = 2.0.0
unix:include(conf.pri)
windows:CONFIG += crypto
windows:include(conf_win.pri)
CONFIG += create_prl
SOURCES = qca-ossl.cpp
windows:{
load(winlocal.prf)
isEmpty(WINLOCAL_PREFIX) {
error("WINLOCAL_PREFIX not found. See http://delta.affinix.com/platform/#winlocal")
}
OPENSSL_PREFIX = $$WINLOCAL_PREFIX
DEFINES += OSSL_097
INCLUDEPATH += $$OPENSSL_PREFIX/include
LIBS += -L$$OPENSSL_PREFIX/lib
LIBS += -llibeay32 -lssleay32
LIBS += -lgdi32 -lwsock32
}
!debug_and_release|build_pass {
CONFIG(debug, debug|release) {
mac:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
}
}
CONFIG += debug
Has anyone got any ideas? If you need anymore details just ask, I've tried to be as thorough as possible. Thanks
Tom
I've been struggling with a similar situation: qca-ossl builds fine on linux and not at all on windows. I just hit a breakthrough which might help you as well.
Versions and Patches
qtsdk-2010.05
qca-2.0.3
qca-ossl-r1190163 (from the repository)
openssl-1.0.0b
First of all, if you're using a newer version (0.9.7+, I think) of OpenSsl, you may need to use the qca-ossl version from the repository since it patches some incompatibilities. I also needed to comment out some lines in the new qca-ossl.cpp file dealing with SHA224, SHA256, SHA384, and SHA512 to avoid build errors. I'm using qca-ossl for the ciphers, so I'm not worried about hashing and didn't investigate the errors very much.
Fixing It
The windows build problems were many fold for me, but most of them stem from the shoddy build setup for the windows version of the plugin. It's nice having a little configure script for the linux side of things, but what about windows? We need to do a little extra work.
Some of this extra work is because I've chosen non-standard locations for the support libraries of my application. Qca and OpenSsl both exist within the project's directory structure in a libraries/ directory. My guess is that you've done something similar if you are trying to cross compile your application, but even if you didn't the following should help.
Finding OpenSsl
Qca-ossl wont build very well if it can't find the library it's supposed to connect to... :) So let's specify directly where it is. Comment out the lines relating to winlocal.prf and the changes that stem from it in qca-ossl.pro. We will directly specify where to find openSsl.
TEMPLATE = lib
CONFIG += plugin
QT -= gui
DESTDIR = lib
VERSION = 2.0.0
unix:include(conf.pri)
windows:CONFIG += crypto
windows:include(conf_win.pri)
CONFIG += create_prl
SOURCES = qca-ossl.cpp
windows:{
# Rather than rely on the winlocal.prf file, we will specify the location of the openssl
# by hand when running qmake.
#
# load(winlocal.prf)
# isEmpty(WINLOCAL_PREFIX) {
# error("WINLOCAL_PREFIX not found. See http://delta.affinix.com/platform/#winlocal")
# }
#
# OPENSSL_PREFIX = $$WINLOCAL_PREFIX
DEFINES += OSSL_097
INCLUDEPATH += $$OPENSSL_PREFIX/include
LIBS += -L$$OPENSSL_PREFIX/lib
LIBS += -llibeay32 -lssleay32
LIBS += -lgdi32 -lwsock32
}
!debug_and_release|build_pass {
CONFIG(debug, debug|release) {
mac:TARGET = $$member(TARGET, 0)_debug
windows:TARGET = $$member(TARGET, 0)d
}
}
Now we have direct access to the $$OPENSSL_PREFIX environment variable in the .pro file. We can set it when we call qmake by doing the following.
qmake.exe "OPENSSL_PREFIX=C:/path/to/openssl-1.0.0b"
You should be able to use backward slashes or forward slashes. Here I choose forward since Qt has deprecated them since 4.7.
Alternatively, you could set the OPENSSL_PREFIX variable directly in the .pro file.
Finding Qca
After comparing the unix and windows makefiles for qca-ossl, oddly enough, it never includes the qca libraries for building or linking! ?!?! This led to an "Undefined interface" error on the Q_INTERFACES(QCAPlugin) line of the opensslPlugin class definition at the end of qca-ossl.cpp.
To avoid this, we will need to explicitly define the include and library paths by hand. Expanding on the qmake line from the last section the final qmake line is as follows.
qmake.exe "OPENSSL_PREFIX=C:/path/to/openssl-1.0.0b" "INCLUDEPATH+=C:/path/to/qca-2.0.3/include/QtCrypto" "LIBS+=-LC:/path/to/qca-2.0.3/lib -lqca2"
"Installing" Qca-ossl
After running the qmake line above and running a plain ol' make, you'll need to install Qca-ossl. You can copy the resulting dll from the lib/ directory to your Qt's plugins directory, which if you're using my versions defaults to C:\Qt\2010.05\qt\plugins\crypto. Alternatively, you can move it to a crypto directory that's at the root level of your project's directory structure such as C:\path\to\my\project\crypto.
I hope this helps!
Actually, you can try this tutorial QCA+OpenSSL on Window. It's work well.
By the way, I can make use of QCA with AES 256 on Window. But i can't use it on Symbian. Any idea to do it?
Related Post