How can I use HKDF library in my qt project? I found this library seems appropriate in qt (I checked with my source), but I couldn't include this header to project.
Adding a library to a Qt project is actually quite simple. In your qmake .pro file you need the following:
# This is the search location for the compiler to look for headers that accompany your library.
# For system libraries that typically resides under **/usr/include** or **/usr/local/include** if you used `make install`.
INCLUDEPATH+="/path/of/headers/for/library"
# This is the search location for the compiler/linker to look for the library itself.
# For system libraries this is usually somewhere under **/usr/lib** or **/usr/local/lib**
LIBS+= -L/path/of/library/itself
# This is the name of the library to include at link time
# without the **lib** prefix and the **.so** / **.a** / **.lib** / **.dll** extension.
LIBS+= -lMyLibraryName
# This is the full path of the library file itself
# *including* the aforementioned **lib** prefix and the **.so** / **.a** / **.lib** / **.dll** extension.
# This is used by qmake to look for changes to the library at build time,
# to make sure it is re-linked on change and other dependency related stuff
PRE_TARGETDEPS += /path/and/filename/of/library/itself/libMyLibraryName.lib
TIP: All the paths, unless they are specified as absolute paths (starting with '/') will be relative to the build directory. This might be the project directory, but in the case of shadow builds, it will be the shadow build directory. As a tip, simply prepend the following to your relative paths to make them relative to project directory: $$_PRO_FILE_PWD_/ so if for example your lib resides in /my/qt/project/libs/mylib you could make your project resilient to moving by using $$_PRO_FILE_PWD_/libs/mylib instead. Please note that the "project dir" is the location of the qmake .pro file.
I use CryptoPP HKDF implementation by https://www.cryptopp.com
Firstly, build static lib for valid architecture and for your platform (MacOS, Android, iOS, etc). CryptoPP Wiki has working manuals and scripts.
Then, just add 2 lines to your qmake *.pro file:
INCLUDEPATH += $$DEV_LIBS_PATH/cryptopp/$$ANDROID_ARCH/include
LIBS += -L$$DEV_LIBS_PATH/cryptopp/$$ANDROID_ARCH/lib -lcryptopp
as you can understand, I used qmake variables DEV_LIBS_PATH and ANDROID_ARCH which are just compose right path to relevant headers and static library libcryptopp.a.
Related
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.
What variables and qmake-commands can I use to install (copy) header files of my qt-project to system's include directory (for example - /usr/include)?
I have tried an approach:
header_files.files = $$HEADERS
header_files.path = project/
INSTALLS += header_files
but it installs files not to include dir (of course because we have not set it). I've searched a variable in QMake Variables but did not found any useful.
You should make header_files.path the directory you want them to install into.
header_files.path = /usr/include
And the files you want to install should be in the header_files.files variable
header_files.files = directory_for_headers/*
Edit: If you need a cross-platform solution, you need to know the default include directories of your target system, and use it like this:
win32: header_files.path = win32_include_directory
linux: header_files.path = linux_include_directory
Edit: But I think if the user compiles with mingw, it should automatically put them in mingw's include directory, so you may need to use either /include or /usr/include. I'm not sure of that though. You need to test it on a Win machine.
I need to build my plugin/library as a .so on Mac. That happens without extra trick on Linux and works like a charm.
What extra options I need to add to my .pro file?
CONFIG += debug
QT += xml
TEMPLATE = lib
TARGET = mylib
DEPENDPATH += .
macx:INCLUDEPATH += ../../../Test \
/usr/local/include/
macx:LIBS += -L../../../Test/lib
DEFINES += CORE_EXPORT=
DEFINES += GUI_EXPORT=
HEADERS += test.h testGui.h
FORMS += testGui.ui
SOURCES += test.cpp testGui.cpp
RESOURCES += test.qrc
The ".so" suffix doesn't mean anything on OS X. On an ELF platform like Linux, an "*.so" file is a shared library. On OS X, shared libraries have the ".dylib" extension. On Linux, plugins are implemented as shared libraries (*.so) because you can unload them again when you're done with them. On OS X, shared libraries cannot be unloaded. That makes them unsuitable for plugins.
On OS X, you use bundles instead of shared libraries in order to implement plugins. Last time I looked, qmake doesn't support this directly. But you can modify the linker flags in order to build a bundle. By default, qmake uses the "-dynamiclib" linker flag, which builds a *.dylib. Instead, you should use the "-bundle" flag, which builds bundles. You can try this:
CONFIG += plugin
QMAKE_LFLAGS_PLUGIN -= -dynamiclib
QMAKE_LFLAGS_PLUGIN += -bundle
The file extension of a bundle is not standardized. You can use whatever you want (.so, .dylib, .plugin, .donald_duck, ...) Apple recommends ".bundle", but doesn't enforce it. To control the filename of the created bundle, you can set QMAKE_EXTENSION_SHLIB and QMAKE_PREFIX_SHLIB. For example, to get mylib.bundle, set:
QMAKE_EXTENSION_SHLIB = bundle
QMAKE_PREFIX_SHLIB =
If instead you want to get libmylib.so, only set:
QMAKE_PREFIX_SHLIB = so
As the names suggest, QMAKE_EXTENSION_SHLIB contains the file extension (without the .), and QMAKE_PREFIX_SHLIB contains the file prefix (by default it's lib).
you may need to put the -dynamiclibs line after bundle... works for me.
found here:
http://jonmacey.blogspot.com/2012/03/using-maya-api-with-qt-creator.html
I require a very simple mechanism in my application, where my project is built as a shared library '.so' or '.dll', but what I want is:
ExampleAppOne.so
I get:
libExampleAppOne.so -> libExampleAppOne.so.1.0.0
libExampleAppOne.so.1 -> libExampleAppOne.so.1.0.0
libExampleAppOne.so.1.0 -> libExampleAppOne.so.1.0.0
I don't even want the 'lib' prefix. In the .pro file, all I can do is change the INSTALLS variable (that is because my third requirement IS that the library be built in a specific directory).
Also, I have a fourth, related requirement: When I ask QLibrary to load the library, I want it to specifically search for a library in a very specific path and a library that matches the EXACT name given to it. No 'lib' prefix matching, no 'version string' searching, no looking into LD_LIBRARY_PATH...
Any help is appreciated.
Regards,
rohan
add the following to you .pro file
# disables the lib prefix
CONFIG += no_plugin_name_prefix
# disable symlinks & versioning
CONFIG += plugin
Adding plugin to the CONFIG variable should disable versioning and the generation of symbolic links to the library.
I don't know of a simple way to disable the lib prefix though. You way want to dig into the provided QMake spec files to see how the default processing is implemented.
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.