2

In my Qt program I have to convert a string to a hash. I want to use OpenSSL on Debian. Little brief of my code:

#include <openssl/sha.h>
...

unsigned char data[] = "data to hash";
unsigned char hash[SHA512_DIGEST_LENGTH];
SHA512(data, sizeof(data) - 1, hash);

I have installed openssl and libssl-dev. And I also have changed my .pro document, looks like that:

TEMPLATE = app
QT = core gui

HEADERS += window.h
PKGCONFIG += openssl //found in another solution, but it does not work
LIBS += -L/usr/share/doc libssl-dev
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

SOURCES +=  main.cpp window.cpp

In LIBS I have tried all possible locations that I get with sudo dpkg -L libssl-dev . Does anyone what I am missing? It doesn't compile and I sure is about that.

Thanks.


Here is the error when linking:

/usr/lib/x86_64-linux-gnu/qt4/bin/qmake -o Makefile App.pro
g++ -m64 -Wl,-O1 -o App main.o window.o moc_window.o    -L/usr/lib/x86_64-linux-gnu -L/usr/share/doc/libssl-dev -libssl-dev -lQtGui -lQtCore -lpthread 
/usr/bin/ld: cannot find -libssl-dev
collect2: error: ld returned 1 exit status
Makefile:105: recipe for target 'App' failed
make: *** [App] Error 1
jww
  • 97,681
  • 90
  • 411
  • 885
Hack Facilito
  • 71
  • 1
  • 8
  • "It doesn't compile" isn't an error description. What error do you get when you try? – SoronelHaetir Jan 13 '18 at 18:21
  • @SoronelHaetir Edited* – Hack Facilito Jan 13 '18 at 18:26
  • 2
    Try to replace `LIBS += -L/usr/share/doc libssl-dev` with `LIBS += -lcrypto` – Dmitry Jan 13 '18 at 18:35
  • [Add OpenSSL support for Linux Qt Application](https://stackoverflow.com/q/47630402/608639), [How to Include OpenSSL in a Qt project](https://stackoverflow.com/q/14681012/608639), [Changing OpenSSL include path for qmake](https://stackoverflow.com/q/20592001/608639), [How to tell Qt to use different OpenSSL](https://stackoverflow.com/q/40429278/608639), [How to implement OpenSSL in Qt?](https://stackoverflow.com/q/43384887/608639), [Is there any way to building static Qt with static OpenSSL?](https://stackoverflow.com/q/20843180/608639), etc – jww Jan 14 '18 at 09:16

1 Answers1

5

In general if the library is libsomelib.so you must import it using -lsomelib, and in your case assuming that you have installed it using the system's tools it is not necessary to pass it a path, just add the following since the library is libssl.so:

LIBS += -lssl -lcrypto

or you can also use pkg-config:

PKGCONFIG += libssl

where /usr/lib/pkgconfig/libssl.pc is:

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: OpenSSL-libssl
Description: Secure Sockets Layer and cryptography libraries
Version: 1.1.0g
Requires.private: libcrypto
Libs: -L${libdir} -lssl
Libs.private: -ldl 
Cflags: -I${includedir}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241