How to Tell Qt to Use Different Openssl

How do I know if Qt links against openssl, and which one?

Qt links some libraries dynamically at runtime. In order to see which libraries are loaded, one can check the diagnostic output of the dynamic linker, as hinted by Matteo:

Say my executable is called QGroundcontrol:

On Linux:

LD_DEBUG=libs ./QGroundcontrol 2>&1 | grep -E "ssl|crypto"

On macOS:

DYLD_PRINT_LIBRARIES=1 ./QGroundcontrol 2>&1 | grep -E "ssl|crypto"

From this I could see that Qt finds openssl on the system.

Now, I still don't know how I can tell Qt to look somewhere else (in case I want to link another openssl), but that's another question.

Use OpenSSL in Qt C++

From the documentation:

QSslSocket::sslLibraryBuildVersionString() Returns the version string of the SSL library in use at compile time. (emphasis mine)

That you get a result from it doesn't mean that Qt has access to OpenSSL, only that it was compiled against a certain version. That lets you know what binary-compatible version you should provide at runtime if it's dynamically linked (as it is by default).

You want to check QSslSocket::sslLibraryVersionNumber() - [...] the version of the library in use at run-time (emphasis mine).

Qt will presumably attempt to find a copy of OpenSSL dlls in PATH, and if not, in the paths given by QCoreApplication::libraryPaths. You should add the location of OpenSSL dlls to either one before attempting to use OpenSSL.

How to Include OpenSSL in a Qt project

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>

OpenSSL in Qt5 on Windows

Using listdlls tool i managed to find the name and location of openssl DLLs. They're libssl-1_1-x64.dll and libcrypto-1_1-x64.dll and located in %QT_INSTALL_PATH%/Tools/QtCreator/bin. Copying those DLLs to the build folder of the project solved the issue.

QtCreator used build environment which is apparently the default environment and can be found in Projects -> Run. It sets a number of environment variables, and in my case exactly, it updated the PATH variable adding the path of QtCreator bin folder.

How to configure OpenSSL on the QT

I am install OpenSSL 32bit, is now working.

Download precompiled for Windows:

http://slproweb.com/products/Win32OpenSSL.html

Downloads:

  • Win32: http://slproweb.com/download/Win32OpenSSL_Light-1_0_2j.exe
  • Win64: http://slproweb.com/download/Win64OpenSSL_Light-1_0_2j.exe

After install copy DLLs (from C:\OpenSSL-Win32 or C:\OpenSSL-Win64, depends on whether you will compile with Qt 32bit or Qt 64bit) for release or debug project folder:

  • libeay32.dll
  • libssl32.dll
  • ssleay32.dll

Note: No need to add anything to "LIBS +="



Related Topics



Leave a reply



Submit