I'm new to Qt, I've done some Googleing and can't find a detailed enough answer.
I need to use OpenSSL in my qmake-based Qt project. How do I go about downloading/installing/linking it so I can just do an include statement and use its functions in my code?
Assuming Windows, you can download its installation from Win32 OpenSSL Installation Project page. You can choose one for 64-bit windows developing or for 32-bit. Just run the setup and everything will be done easily. The default installation directory is : C:\OpenSSL-Win32
In Qt creator, if you then want to link a library to your project you can just add this line to your .pro file(project file ) :
LIBS += -L/path/to -llibname
So here's what we do for this library( for example to link ubsec.lib )
LIBS += -LC:/OpenSSL-Win32/lib -lubsec
Pay attention to -L and -l.See this question. You don't even need to specify .lib at the end of the library name.
For including .h files add this line to your .pro file :
INCLUDEPATH += C:/OpenSSL-Win32/include
after that you can include a file like this :
#include <openssl/aes.h>
From George at Unable to use AES files of OpenSSL in Qt Creator:
If this is on Linux, add the following into your .pro file:
PKGCONFIG += openssl
It will handle all necessary header paths, compile-linker options and
the libraries.
And make sure you have the openssl-devel package installed in your
system.
I was working on Win 7 (32) with Qt5.5, and non of these answers worked for me.
So I just want to share a solution that finally worked:
1. I have OpenSSL installed in C:\OpenSSL-Win32
2. In c:\OpenSSL-Win32\MinGW there are two library files:
libeay32.a & ssleay32.a
3. I've made a copy of each of them an renamed the extensions:
libeay32.a -> libeay32.lib & ssleay32.a -> ssleay32.lib
4. I linked libraries in my .pro file this way:
LIBS += -LC:/OpenSSL-Win32/lib/MinGW -llibeay32
LIBS += -LC:/OpenSSL-Win32/lib/MinGW -lssleay32
INCLUDEPATH += C:/OpenSSL-Win32/include
5. I copied 3 .dll files from C:\OpenSSL-Win32:
(libeay32.dll, libssl32.dll, ssleay32.dll)
to my build/debug folder:
(build-XXXXX-Desktop_Qt_5_5_1_MSVC2012_32bit-Debug/debug)
I hope this will help.
If you use cmake as build system for your project, then you may include FindOpenSSL.cmake as follows:
#set(OPENSSL_USE_STATIC_LIBS TRUE) # if you want to use static libssl.a and libcrypto.a
include(FindOpenSSL)
#add_executable(${PROJECT_NAME} ...) or add_library(${PROJECT_NAME} ...)
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_DL_LIBS} OpenSSL::SSL OpenSSL::Crypto)
${CMAKE_DL_LIBS} is required on Linux systems to avoid link-time errors like "dlopen symbol not found...". On windows it became empty.
If openssl installation directory is not being standard, then you should provide OPENSSL_ROOT_DIR to cmake, e.g. to add set(OPENSSL_ROOT_DIR "C:/msys64/mingw32") before include or to specify -DOPENSSL_ROOT_DIR:PATH=C:/msys64/mingw32 to cmake executable (in "Projects"->"Build settings"->"CMake" tab).
if you are on win7,and your qt version is mingw, and u install openssl from http://slproweb.com/products/Win32OpenSSL.html ,make sure your lib should be in the OpenSSL-Win32/lib/MinGW, and add a "lib" pre to the libeay32.a and ssleay32.a 。
Related
Qt seems to load openssl dynamically at runtime, as seen in this question.
And apparently, it gets the system openssl. For instance, on macOS, I would rather use the homebrew-installed openssl, and package it into my dmg, so that the users don't need to install it themselves.
How can I tell Qt where to look for the libraries it links? Is there something to do with the qt.conf file?
you can do something like that in your .pro file:
win32-msvc* {
LIBS += -LC:/openssl/lib/ -llibeay32
LIBS += -LC:/openssl/lib/ -lssleay32
INCLUDEPATH += C:/openssl/include
}
left click on your project -> add library -> external library -> choose the .lib file and the include folder for the library. check for which platform it is.
It will put the specific platform dependend commands to your project .pro filefile.
ANN: Approximate Nearest Neighbor Searching.
I am using QT creator in windows-10 64 bit system. I have compiled the source files from official site of ANN with visual studio 2015 and have successfully run the sample and test with the same environment. That is also the way how I get dll and lib files.
However, I tried to add the library to my QT creator but failed. I used both external library and internal library, even tried system library, but the problem of ' cannot open' always shows up. Meanwhile, I tried put all .h files, dll and lib file in the project's directory, still the same problem. All of other external libraries work fine after I configure them in my qmake file. Here is an example:
LIBS += -lopengl32
This is an internal lib I added (maybe system lib). And:
win32:CONFIG(release, debug|release): LIBS += -LC:/local/boost_1_63_0/lib64-msvc-14.0/ -lboost_filesystem-vc140-mt-gd-1_63
-llibboost_filesystem-vc140-mt-s-1_63
-llibboost_serialization-vc140-mt-s-1_63
-llibboost_system-vc140-mt-s-1_63
else:win32:CONFIG(debug, debug|release):
LIBS += -LC:/local/boost_1_63_0/lib64-msvc-14.0/
INCLUDEPATH += C:/local/boost_1_63_0
DEPENDPATH += C:/local/boost_1_63_0
As you can see, the two above libraries are working perfectly. Again, as I mentioned, my VS2015 can compile the sample by the library I put in the system directories. So how should I configure ANN lib in my QT?
I solved the main part of this problem by the suggestion made by the dude who commented above. Thanks a lot! The situation currently is that I can run the ANN.lib correctly in my QT creator with several other libraries (without compiling errors).
As I mentioned, I have already put all necessary files into the system directories, such as dll(system32), .lib(my visual studio 14/VC/lib), .h(my visual studio 14/VC/include). But that seemed not enough to run the ANN.lib successfully.
So I added a configuration of compilation, which is x64 release, to generate the newest dll and lib. Then I did the last step again, still not working. After that I put all files in single directory located in disk C and add this path to my qmake as external library. Now it works. Although I didn't delete the ones in my system's directories, it is running. Another thing I wonder to mention is that I also add this path to environment variables, so that I can just use += -lANN to run the lib without making it as external library. Both can work fine.
I am working in embedded system domain and i was trying to cross-compile a QT- program for the ARMv7 platform.
I am using the following cross-compiler ---
" angstrom-2011.03-x86_64-linux-armv7a-linux-gnueabi-toolchain-qte-4.6.3.tar "
I had all the shared libraries required by the program inside /usr/lib folder ( I am using Angstrom-linux in my target platform ) so i guess there is no need to give path of my shared libraries to the loader. But still it is showing some error that some of the shared libraries require GLIBC_2.9 ( "error : GLIBC_2.9 not found" ). I don't have a gcc compiler for my target platform so i am cross-compiling my programs, is that the reason ???????????
This is what you should do in a qmake based project for cross-compiling in your scenario:
qmake -r -spec linux-arm-gnueabi-g++
and the qmake project file should contain this:
LIBS += /usr/local/.../lib # path to your embedded target libraries
Note that you may also need to set up the following variable, too, for having the includes right:
INCLUDEPATH += /usr/local/.../include # path to your embedded target headers
I compiled a library using the MinGW toolchain provided with Qt 5.0.2 on Windows. As a result I received a library.so file. First I failed using the library in a Qt application, but now I found out that everything works fine when I make a copy of the liblibrary.so file and call it liblibrary.dll or liblibrary.lib (which is the only file ending supported by the add library wizard in QtCreator).
Now I wonder if this is normal or if I should change something in order not to have both files (which are exact copies). Leaving one away makes the application crash during start up. I added the library as follows to my Qt pro file:
LIBS += -L"../path/to/library" -llibrary
INCLUDEPATH += $$quote(../path/to/library)
EDIT: I compiled the library using the MinGW of Qt, not as Qt project but using mingw32-make and the provided Makefile. As a result I get the liblibrary.so.
EDIT: It seems to work also when renaming the copy to liblibrary.dll instead of .lib. But still, I need two files to make the application work -- the .so and the .dll.
Chris
That's weird, I think you should get a *.a and *.dll files when building a shared lib with MinGW on Windows, as said in the documentation:
In windows, MinGW will output .a and .dll, MSVC2010 will ouput .lib and .dll. In linux, MinGW will output .so, .so.1, .so.1.0 and .so.1.0.0 – .lib, .a and .so are import libraries.
You definitely shouldn't rename your file!
Be careful to:
not to include the "lib" prefix after "-l" in your project file.
put everything after after "-l" in lower case as you're on Windows
not adding any extension to your library name after "-l"
add and reference the .h file used in your library
A real example using QtWebsocket lib:
INCLUDEPATH += "$${PWD}/include/"
LIBS += -L"$${PWD}/libs/" -lqtwebsocket
...
HEADERS += ... \
$${PWD}/include/QWsSocket.h \
...
In my include/ folder, I have the following file:
QWsSocket.h (taken from original project - required)
In my libs/ folder, I have the following file:
libQtWebsocket.a
QtWebsocket.dll
Edit: I struggled with this too initially. Have you tried to build your lib as a static lib instead (CONFIG += staticlib in your library project)? This might help you getting you *.pro file right before switching to using the shared library.
Edit 2: Ok, the fact that you get a *.so file is still a bit odd. In this question
the user has the same issue as you and keep both files, which is just a workaround. According to a later answer it seems that you need to modify your makefile to generate a file with the proper extension. Maybe this will help: http://www.mingw.org/wiki/sampleDLL
I use LIBS flag to link qwt library to my project. So in .pro of my project i have
LIBS += -L/home/Desktop/qwt-6.0.1/lib -lqwt
But anyway Qt does not recognize qwt classes. What i'm missing ??
I think you forgot to include the headers.
Try to add the following
INCLUDE += /home/Desktop/qwt-6.0.1/include
I had same problem. you have to use -L switch and set your library path as bellow:
LIBS+= -L "/home/Desktop/qwt-6.0.1/lib/" -lqwt
adding above line to the .pro file resolve compiling error of the project. then for running Application you should link libqwt.so.6.1.3 to default library path on your system using bellow command:
ln -s /home/Desktop/qwt-6.0.1/lib/libqwt.so.6.1.3 /usr/lib/libqwt.so.6
or simply update LD_LIBRARY_PATH using below command:
export LD_LIBRARY_PATH=/home/Desktop/qwt-6.0.1/lib/lib:$LD_LIBRARY_PATH
I advice you to use the first approach.