Qt笔记-Centos7搭建OpenSSL开发环境及Qt调用OpenSSL实例

x33g5p2x  于2022-07-07 转载在 其他  
字(1.4k)|赞(0)|评价(0)|浏览(414)

这里Centos上已经安装好了Qt5.5.1

下面搭建下OpenSSL

首先下载并安装zlib

wget http://zlib.net/zlib-1.2.12.tar.xz
xz -dk zlib-1.2.12.tar.xz 
tar -xvf zlib-1.2.12.tar
cd zlib-1.2.12/
 ./configure --prefix=/usr/local
 make && make install

再安装 perl-Test-Harness

yum install perl-Test-Harness

随后下载openssl-1.1.1o并安装:

wget https://www.openssl.org/source/openssl-1.1.1o.tar.gz --no-check-certificate
tar -zxvf openssl-1.1.1o.tar.gz
cd openssl-1.1.1o/
./config --prefix=/usr/local/ssl shared zlib-dynamic enable-camellia
make depend
make test
make
make install

完成好后设置好环境变量

PATH=/usr/local/ssl/bin:$PATH
export PATH
cd /etc/ld.so.conf.d/
vim ssl.conf

在ssl.conf中添加如下内容:

/usr/local/ssl/lib

最后运行:

ldconfig
openssl version

就可以看到OpenSSL版本了

创建Qt项目:

OPenSSLDemo.pro

QT += core
QT -= gui

TARGET = OpenSSLDemo
CONFIG += console
CONFIG -= app_bundle

INCLUDEPATH += /usr/local/ssl/include
LIBS += -L /usr/local/ssl/lib/ -lssl -lcrypto

TEMPLATE = app

SOURCES += main.cpp

main.cpp

#include <QCoreApplication>
#include <openssl/crypto.h>
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    std::cout << OpenSSL_version(0) << std::endl;
    std::cout << OpenSSL_version(1) << std::endl;
    std::cout << OpenSSL_version(2) << std::endl;
    std::cout << OpenSSL_version(3) << std::endl;
    std::cout << OpenSSL_version(4) << std::endl;
    std::cout << OpenSSL_version(5) << std::endl;

    return a.exec();
}

运行截图如下:

源码打包下载地址:

Qt/OpenSSLDemo at master · fengfanchen/Qt · GitHub

高性能云服务器

精品线路独享带宽,毫秒延迟,年中盛惠 1 折起

相关文章