Hac*_*ito 2 c++ qt openssl pkg-config libs
在我的 Qt 程序中,我必须将字符串转换为哈希值。我想在 Debian 上使用 OpenSSL。我的代码的简短介绍:
#include <openssl/sha.h>
...
unsigned char data[] = "data to hash";
unsigned char hash[SHA512_DIGEST_LENGTH];
SHA512(data, sizeof(data) - 1, hash);
Run Code Online (Sandbox Code Playgroud)
我已经安装了 openssl 和 libssl-dev。我还更改了我的 .pro 文档,如下所示:
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
Run Code Online (Sandbox Code Playgroud)
在 LIBS 中,我尝试了所有可能的位置sudo dpkg -L libssl-dev。有人知道我缺少什么吗?它无法编译,我确信就是这样。
谢谢。
这是链接时的错误:
/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
Run Code Online (Sandbox Code Playgroud)
一般来说,如果库是,libsomelib.so则必须使用 - 导入它lsomelib,并且在您的情况下,假设您已使用系统工具安装了它,则无需向其传递路径,只需添加以下内容,因为库是libssl.so:
LIBS += -lssl -lcrypto
Run Code Online (Sandbox Code Playgroud)
或者你也可以使用 pkg-config:
PKGCONFIG += libssl
Run Code Online (Sandbox Code Playgroud)
哪里/usr/lib/pkgconfig/libssl.pc:
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}
Run Code Online (Sandbox Code Playgroud)