7

I got a sample projct that uses QSslSocket and QSslCertificate to get information from a SSL certificate (Qt 5.7, Windows 10). QSslSocket::supportsSsl() function returns false and I get these errors at runtime:

qt.network.ssl: QSslSocket: cannot call unresolved function SSLv23_client_method
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_new
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_library_init
qt.network.ssl: QSslSocket: cannot call unresolved function ERR_get_error

So I compiled OpenSSL_1.1.0 and linked it to my project:

INCLUDEPATH += . "C:/OpenSSL-Win32/include/" LIBS +=
-L"C:/OpenSSL-Win32/lib/" -llibcrypto -llibssl

But still same errors. I downloaded OpenSSL installer and still the same.

Weird is QSslSocket::sslLibraryBuildVersionString() returns OpenSSL 1.0.2g 1 Mar 2016, even though I compiled and installed OpenSSL_1.1.0.

I know I'm missing a simple detail. Please tell me what is it. Thanks.

12
  • The INCLUDEPATH is unnecessary, of course, since you don't compile any code using openssl directly. All you need is the LIBS += ... line. If openssl is compiled as a dynamically linked library, you not only need to add its import library in the .pro file, but you also need to ensure that it's in the path when you run your project! Commented Sep 14, 2016 at 15:22
  • I removed INCLUDEPATH and kept LIBS in .pro file. Added OpenSSL's bin directory in %PATH%. Still QSslSocket::supportsSsl() returns false and QSslSocket::sslLibraryVersionString() returns OpenSSL 1.0.2g 1 Mar 2016 even though I compiled OpenSSL 1.1.0 Commented Sep 14, 2016 at 15:38
  • Add qDebug() << qgetenv("PATH"); to main() and ensure that your library path appears there and that it is correct. Copy-paste the library path from the debug output to an explorer window and make sure it's valid. Commented Sep 14, 2016 at 15:46
  • It has C:\\OpenSSL-Win32\\lib but it's not valid. Recently I deleted everything and built OpenSSL from scratch in C:\openssl_1.1.0. How can I change it? I couldn't find its setting. Commented Sep 14, 2016 at 16:21
  • Read up on superuser how to set environment variables on Windows. Such question is truly off-topic here. Commented Sep 14, 2016 at 18:00

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok, so I should provide OpenSSL 1.0.2g DLLs and put them in PATH to make my application work. Can you tell me what is exact DLLs that my application needs?
You don't put "dlls" in PATH, you add the bin subfolder of OpenSSL's install prefix to the PATH. So, suppose you built OpenSSL 1.0.2h (newest 1.0.2 you can get - all 1.0.2 are binary compatible), and set the prefix as C:\OpenSSL. Then, add C:\OpenSSL\bin to PATH or libraryPaths.
The problem was i was putting 32-bit libeay32.dll and ssleay32.dll files beside my application. When I installed Win64-OpenSSL and copied mentioned DLLs beside my application, it worked. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.