18

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?

jww
  • 97,681
  • 90
  • 411
  • 885
Mitch
  • 519
  • 2
  • 7
  • 16

5 Answers5

25

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>
dlmeetei
  • 9,905
  • 3
  • 31
  • 38
s4eed
  • 7,173
  • 9
  • 67
  • 104
  • Thanks a lot. That's the type of answer I've been looking for. – Mitch Feb 04 '13 at 15:58
  • 1
    What is `ubsec.lib`, and what does it have to do with linking OpenSSL? – jww May 06 '17 at 21:30
  • @jww Just an example. – s4eed May 07 '17 at 09:08
  • 1
    The setup of the "OpenSSL installation project" defaults to adding the dll's to system directories, and this way the correct dll's are also found, but only if this option was checked during setup. Otherwise there will likely be a dll from somewhere on the build system which is loaded by accident. I suggest to add deployment of the dll's to the build output directory additional to these steps, in order to avoid such issues. – FourtyTwo Sep 11 '17 at 14:28
  • There's an interesting phrase under "donations": Businesses integrating Win32 OpenSSL into products must pay a minimum of $225 to help cover the cost of bandwidth. – FourtyTwo Sep 11 '17 at 15:23
  • I'm pretty sure this isn't the best solution possible. QT is all about portability. Now hardwiring a directory path into the source (e.g. the .pro file) isn't portable at all. – Imre Dec 07 '18 at 00:02
  • @Imre Yeah for sure. If you want to be portable in .pro file too, you have to write inclusion of library conditionally based on the current operating system. – s4eed Dec 07 '18 at 21:20
  • @s4eed also you can't expect EVERYBODY using the same OS to have openssl installed into the same directory (at least not on windows for instance) – Imre Dec 07 '18 at 21:50
  • @Imre, Yeah for sure :D, It's just the imperfect solution to show the way to solve the problem to the questioner, with the least complexity. But thanks man for your advice. – s4eed Dec 08 '18 at 07:44
8

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.

Stypox
  • 963
  • 11
  • 18
jww
  • 97,681
  • 90
  • 411
  • 885
4

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.

RogerT
  • 61
  • 1
  • 7
1

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).

Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169
0

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 。

loc
  • 1
  • 1
  • 1
  • 1
    It looks like a good answer, but can you be a little more clear please. Tx. – K.Nicholas Apr 12 '16 at 13:15
  • sorry, long time since last login. you can first follow this http://stackoverflow.com/a/14681524/6193558 then changed the name of the two files :libeay32.a ssleay32.a. I solved this problem while refer other's solution. hope can help you. – loc Jan 02 '17 at 04:10