Trying to link OpenSSL libraries under Windows



  • Hello!

    I am making a project which requires both Windows and Linux compilation. It worked fine until I tried to include OpenSSL functions. I have been stuck for days on that issue and I can't seem to be able to find a solution.

    On Linux, everything works fine (I yum-installed openssl-devel and crypto-devel). I just needed to add
    @LIBS += -lcrypto -lssl@

    On Windows, I installed OpenSSL (Both in system path and "C:\OpenSSL-Win32")
    I added
    @INCLUDEPATH += C:\OpenSSL-Win32\include@
    which seems to work fon linking headers.

    with
    @LIBS += -lcrypto -lssl@
    I get
    @:-1: error: cannot find -lcrypto@

    with
    @LIBS += -LC:\OpenSSL-Win32\lib@
    I get
    @documentmanager.cpp:21: error: undefined reference to `AES_set_encrypt_key'@

    I tried a combinaison of both:
    @LIBS += -L"C:\OpenSSL-Win32" -lcrypto -lssl@
    And I get
    @:-1: error: cannot find -lcrypto@

    Can anyone help me?

    EDIT: Qt creator is installed with the Qt 5.0.1 and MingW version

    Thank you!


  • Lifetime Qt Champion

    Hi,

    The right path is indeed "C:/OpenSSL-Win32/lib" (better with / even on windows)
    AES_set_encrypt_key missing means that there might be something not right with your installed OpenSSL. Which version did you install ? And do you compile you application as 32bit ?



  • Hello!

    Thank you for your answer. Now my LIBS line is this:
    @LIBS += -L"C:/OpenSSL-Win32/lib" -lssl -lcrypto"@
    but I still get
    @:-1: error: cannot find -lssl
    :-1: error: cannot find -lcrypto
    collect2.exe:-1: error: error: ld returned 1 exit status@

    And if I remove -lssl and -lcrypto
    @LIBS += -L"C:/OpenSSL-Win32/lib"@
    then I get
    @C:\Users\Max\Prog\ift_6001-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug\debug\documentmanager.o:-1: In function ZN15DocumentManagerC2EP5QFile': C:\Users\Max\Prog\CryptoSh\Document\documentmanager.cpp:21: error: undefined reference toAES_set_encrypt_key'
    ...
    collect2.exe:-1: error: error: ld returned 1 exit status@

    I installed OpenSSL with the installer here: http://slproweb.com/products/Win32OpenSSL.html

    The project is configured for 32bits. (But I also installed the 64bits OpenSSL just in case.)

    Would it help to recompile the whole Qt Framework with openssl support, or it is not relevant to my case?


  • Lifetime Qt Champion

    I don't have my Windows machine at hand to check. Can you verify the name of the libs ?
    And if i'm not mistaken you might have to also link to libeay32 (LIBS += -llibeay32)



  • Thank you so much!

    It works now! The answer was:

    @LIBS += -L"C:/OpenSSL-Win32/lib" -llibeay32@

    Thanks again!


  • Lifetime Qt Champion

    Your welcome !

    Don't forget to update the thread subject to solved



  • I am having an issue with this as well.

    I am trying to display Google Maps within a Qt 5.1 WebView but nothing displays and I received this message on the console:

    Unable to init SSL Context:

    I was told I needed to link with OpenSSL so I followed the instructions in this thread but I still reveive the same error above.

    I am not getting any compile or link errors so what else might I have to do to get HTTPS (which requires SSL) to work?



  • Are you linking ssleay32 too?



  • I have it working now. The problem seemed to be the way I installed OpenSSL. Initially I chose the option to install the DLLs into a subdirectory of where I installed OpenSSL but this option didn't work. When I reinstalled OpenSSL and chose the other option to have them installed into the Windows System directory I was able to get SSL happening and the Google Maps application started working.

    I am concerned about this. It is important to me that I am able to ship my Qt application with everything it needs to run on each environment. I do not wish to have my users have to install OpenSSL into their Windows System folder for my application to run successfully.

    Is there a way to use OpenSSL in a Qt application on Windows without forcing the end user to install OpenSSL? Would my first approach have worked if I had somehow referenced the OpenSSL binaries in the Qt project?


  • Moderators

    [quote author="Qu0ll" date="1374351495"]Initially I chose the option to install the DLLs into a subdirectory of where I installed OpenSSL but this option didn't work. When I reinstalled OpenSSL and chose the other option to have them installed into the Windows System directory I was able to get SSL happening and the Google Maps application started working.[/quote]It sounds like simply a case of your application being unable to find DLLs. When you installed them to the Windows System folder, that worked because ALL Windows apps look there. However, this method is a relic from Windows 98 times and is frowned upon now for security reasons -- only Windows should mess with the Windows folders; user apps should put their files elsewhere and (maybe) modify the PATH variable.

    [quote]I am concerned about this. It is important to me that I am able to ship my Qt application with everything it needs to run on each environment. I do not wish to have my users have to install OpenSSL into their Windows System folder for my application to run successfully.

    Is there a way to use OpenSSL in a Qt application on Windows without forcing the end user to install OpenSSL? Would my first approach have worked if I had somehow referenced the OpenSSL binaries in the Qt project?[/quote]The traditional method for deploying applications on Windows is simply to bundle all required DLLs with the program. This includes the Qt DLLs. See "this page":http://qt-project.org/doc/qt-5.1/qtdoc/deployment-windows.html for more info.

    However, keep in mind that the Qt Project did not bundle OpenSSL for a reason. Please check if there are any "legal implications":http://security.stackexchange.com/questions/3378/is-strong-cryptography-legal-across-the-internet if you distribute it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.