QT5, OpenSSL, MSVC2019, CMAKE can't get it to work.
-
I have been try-ing to get ssl working with my app, I tried every tutorial or post I could find but I can not get this to work.
I removed all related $PATH entries from my dev machine in order to replicate a client machine. I can get every dll to work by just copying it into my build dir using a POST_BUILD command, yet SSL doesn't seem to work.One thing I just found was that according to CMAKE "OPENSSL_APPLINK_SOURCE" should be set for MSVC builds, yet for me it doesn't seem to be set.
Can anyone maybe give me a hint?
Qt5.15
OpenSSL 1.1g installed through maintenance-tools from QT
CMake >=3.16
MSVC2019main.cpp
int main(int argc, char *argv[]) { qDebug() << "Support SSL: " << QSslSocket::supportsSsl(); qDebug() << "sslLibraryBuildVersionString: " << QSslSocket::sslLibraryBuildVersionString(); qDebug() << "sslLibraryVersionString " << QSslSocket::sslLibraryVersionString(); return 1; // just exit here for now. // <snip>....</snip> }
CMakeList.txt
set(Qt5_DIR "${STK_QT_DIR}/msvc2019_64/lib/cmake/Qt5") set(CMAKE_PREFIX_PATH "${STK_QT_DIR}/msvc2019_64/bin") include_directories("${STK_QT}/msvc2019_64/bin") set(OPENSSL_ROOT_DIR ${STK_SSL_DIR}) include(FindOpenSSL) message(WARNING "FindSSL found: ${OPENSSL_FOUND}") message(WARNING "FindSSL include dir: ${OPENSSL_INCLUDE_DIR}") message(WARNING "FindSSL crypto lib: ${OPENSSL_CRYPTO_LIBRARY}") message(WARNING "FindSSL Crypto dependencies: ${OPENSSL_CRYPTO_LIBRARIES}") message(WARNING "FindSSL SSL lib: ${OPENSSL_SSL_LIBRARY}") message(WARNING "FindSSL SSL dependencies: ${OPENSSL_SSL_LIBRARIES}") message(WARNING "FindSSL ALL : ${OPENSSL_LIBRARIES}") message(WARNING "Mysterious appLink : ${OPENSSL_APPLINK_SOURCE}") add_executable(boom ${STK_SRC_DIR}/main.cpp ) target_link_libraries(${STK_CURRENT_TARGET} PRIVATE OpenSSL::SSL OpenSSL::Crypto OpenSSL::applink) target_link_libraries(${STK_CURRENT_TARGET} PRIVATE ${STK_REQUIRED_LIBS_QUALIFIED}) set_target_properties(${STK_CURRENT_TARGET} PROPERTIES AUTORCC_OPTIONS "--compress;9") set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP FALSE) # Doesn't really seem to install anything anyways set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS "${STK_SSL_DIR}bin/libssl-1_1-x64.dll" "${STK_SSL_DIR}bin/libcrypto-1_1-x64.dll" # we could even add the esri libs in here... lets do that.. ${ArcGISRuntime_LIBRARIES} ) # We can append dll's that aren't detected by the compiler here. include(InstallRequiredSystemLibraries) message(STATUS "DLL's to copy: ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}") # bluntly copy the dll to the build dir, same location as the esri dll's add_custom_command(TARGET ${STK_CURRENT_TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} $<TARGET_FILE_DIR:${STK_CURRENT_TARGET}>)
when running CMAKE all seems "good"
-- Found OpenSSL: C:/Qt/Tools/OpenSSL/Win_x64/lib/libcrypto.lib (found version "1.1.1j") -- FindSSL found: TRUE -- FindSSL include dir: C:/Qt/Tools/OpenSSL/Win_x64/include -- FindSSL crypto lib: C:/Qt/Tools/OpenSSL/Win_x64/lib/libcrypto.lib -- FindSSL Crypto dependencies: C:/Qt/Tools/OpenSSL/Win_x64/lib/libcrypto.lib -- FindSSL SSL lib: C:/Qt/Tools/OpenSSL/Win_x64/lib/libssl.lib -- FindSSL SSL dependencies: C:/Qt/Tools/OpenSSL/Win_x64/lib/libssl.lib -- FindSSL ALL : C:/Qt/Tools/OpenSSL/Win_x64/lib/libssl.lib;C:/Qt/Tools/OpenSSL/Win_x64/lib/libcrypto.lib -- FindSSL appLink : -- The C compiler identification is MSVC 19.32.31332.0 -- The CXX compiler identification is MSVC 19.32.31332.0 ...... -- DLL's to copy: C:/Qt/Tools/OpenSSL/Win_x64/bin/libssl-1_1-x64.dll;C:/Qt/Tools/OpenSSL/Win_x64/bin/libcrypto-1_1-x64.dll;C:/Program Files (x86)/ArcGIS SDKs/Qt100.14/sdk/windows/x64/bin/EsriCommonQtd.dll;C:/Program Files (x86)/ArcGIS SDKs/Qt100.14/sdk/windows/x64/bin/runtimecore.dll;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Redist/MSVC/14.32.31326/x64/Microsoft.VC143.CRT/msvcp140.dll;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Redist/MSVC/14.32.31326/x64/Microsoft.VC143.CRT/msvcp140_1.dll;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Redist/MSVC/14.32.31326/x64/Microsoft.VC143.CRT/msvcp140_2.dll;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Redist/MSVC/14.32.31326/x64/Microsoft.VC143.CRT/msvcp140_atomic_wait.dll;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Redist/MSVC/14.32.31326/x64/Microsoft.VC143.CRT/msvcp140_codecvt_ids.dll;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Redist/MSVC/14.32.31326/x64/Microsoft.VC143.CRT/vcruntime140_1.dll;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Redist/MSVC/14.32.31326/x64/Microsoft.VC143.CRT/vcruntime140.dll;C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Redist/MSVC/14.32.31326/x64/Microsoft.VC143.CRT/concrt140.dll
*Notice that OPENSSL_APPLINK_SOURCE is empty, while docs say on msvc it should hold a value.
After building (release, just to ignore any debugging related complications), all required .dll files are next to my .exe in the build directory.
I can execute the full main file that includes my QT application, everything works correctly... except for ssl.
Commenting out all my code just leaving the main.cpp as shown above the output is:Support SSL: false sslLibraryBuildVersionString: "OpenSSL 1.1.1g 21 Apr 2020" sslLibraryVersionString ""
The dll files in my build dir are:
- concrt14.dll
- EsriCommonQt.dll
- libcrypto-1_1-x64.dll
- libssl-1_1-x64.dll
- msvcp140.dll
- msvcp140_1.dll
- msvcp140_2.dll
- msvcp140_atomic_wait.dll
- msvcp140_codecvt_ids.dll
- runtimecore.dll
- vcruntime140.dll
- vcruntime140_1.dll
- boom.exe
I have had SSL working on my development machine, probably because I added to path the the OpenSSL dir to my system $PATH env.
Yet I can not force my users to install SSL on their desktop machines, so I want to add all required libs manually.
I tried to manually copy all dll files from my OpenSSL dir into my build dir, but it doesn't help.
I also have run this config and appending a proper windeployqt() command, this adds most required QT libs but doesn't change anything on the SSL problem.Is there anyone that can give me a hint or direction?
I tried dependency walker but I can't find anything use-full in there other then hundreds of MS-API-* warnings, even when my app is functioning correctly. -
@huppeldepup said in QT5, OpenSSL, MSVC2019, CMAKE can't get it to work.:
int main(int argc, char *argv[]) {
qDebug() << "Support SSL: " << QSslSocket::supportsSsl();
qDebug() << "sslLibraryBuildVersionString: " << QSslSocket::sslLibraryBuildVersionString();
qDebug() << "sslLibraryVersionString " << QSslSocket::sslLibraryVersionString();
return 1; // just exit here for now.
// <snip>....</snip>
}Construct QApplication before you do anything else. QObjects, QStrings etc. won't function properly without it - so it is also possible QSslSocket won't report correct values without qApp instance.
Is there anyone that can give me a hint or direction?
Try renaming the DLLs (remove -x64 from the name).
-
@huppeldepup said in QT5, OpenSSL, MSVC2019, CMAKE can't get it to work.:
int main(int argc, char *argv[]) {
qDebug() << "Support SSL: " << QSslSocket::supportsSsl();
qDebug() << "sslLibraryBuildVersionString: " << QSslSocket::sslLibraryBuildVersionString();
qDebug() << "sslLibraryVersionString " << QSslSocket::sslLibraryVersionString();
return 1; // just exit here for now.
// <snip>....</snip>
}Construct QApplication before you do anything else. QObjects, QStrings etc. won't function properly without it - so it is also possible QSslSocket won't report correct values without qApp instance.
Is there anyone that can give me a hint or direction?
Try renaming the DLLs (remove -x64 from the name).
@sierdzio Hi, Thanks for your tips!
main(){}
Yes, you are right.
Placing it just before my exec(), I am getting: (the constructor or show method of one of my views makes the https requests)qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
Support SSL: false
sslLibraryBuildVersionString: "OpenSSL 1.1.1g 21 Apr 2020"
sslLibraryVersionString ""The renaming sounded like a possible solution so I renamed both libs to whatever I could think of, unfortunately no difference ;(
I duplicated the files and renamed them so I have all combinations in my build dir now:- libcrypto-1_1-x64.dll
- libssl-1_1-x64.dll
- libcrypto-1_1.dll
- libssl-1_1.dll
- libcrypto-x64.dll
- libssl-x64.dll
- libcrypto.dll
- libssl.dll
Doesn't seem to make a difference.
Is the maybe like a tool or a log that I can use to see what dll it is trying to load?
I tried some but non of them really tells me anything useful. -
Just an update:
I formatted my harddrive and reinstalled windows.
Running (the same) makefile now generates a installer packages that I can successfully install and run on the host machine. I cleaned some stuff up and learned alot about CMAKE and CPACK.Yet unfortunatly,
On my VM, which is a clean Microsoft developer VM, I still get the SSL errors.On a clean, freshly installed windows computer.
What do I need to install/provide in order to run a msvc2019 built Qt5 program with OpenSSL? -
Fixed it!!
In order to get OpenSSL to work you need MSVC2010.
Al due MS says it is part of SP1, it seems it is not and because we are living in 2022 right now, with the redistributable of today... 2010 is not supported (goes back to 2015).So in order to get this to work, you need to manually copy the dll from your windows32 dir.
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS "${STK_SSL_DIR}bin/libssl-1_1-x64.dll" "${STK_SSL_DIR}bin/libcrypto-1_1-x64.dll" "C:/Windows/system32/msvcr100.dll" # REQUIRED for OpenSSL ) include(InstallRequiredSystemLibraries) add_custom_command(TARGET ${STK_CURRENT_TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} ${TMP_DIR} COMMENT "Deploying system DLL's" )
Hope this helps someone in the future.
-
-
I also using MSVC and QT6
For me also the same issue or
-
I also using MSVC and QT6
For me also the same issue or
@srinath_ramamoorthy
This thread shows an error at runtime. You show an error at link time. They are quite separate issues. -
@srinath_ramamoorthy
This thread shows an error at runtime. You show an error at link time. They are quite separate issues.@JonB any solution for this issue MSVC with QT6 complier this issue not in Linux with GCC with QT6