vs2017(Windows平台上VS2017CMake编译LibreSSL)

admin 1064 2022-09-18 13:05:03

前言

今天(2022.5.23)看了下LibreSSL,从github上下载源码编译了下v3.5.3,总结了下编译步骤分享给大家。

准备环境

a. Windows 11 家庭中文版 21H2

b. Visual Studio 2017 社区版

c. CMake 3.23.1

d. Git 2.35.1

编译步骤

a. 下载LibreSSL

git clone git@github.com:libressl-portable/portable.git libressl-portablegit checkout v3.5.3 // 切换目录cd libressl-portable

b. 下载 OpenBSD

Source code pulled from OpenBSD for LibreSSL - this includes most of the library and supporting code.

git clone git@github.com:libressl-portable/openbsd.git// 切换分支,定义在 "libressl-portable/OPENBSD_BRANCH"git checkout OPENBSD_7_1

说明:这里本来可以通过update.sh来自动下载代码和预处理的,当时因为脚本使用的是https路径下载失败,后来自己手动改的ssh方式,这里就调整了下顺序

c. 修改 objects.txt 文件,原因是该文件以“\r\n”结尾,导致 perl 运行失败,需要将“\r\n”全部替换为“\n”

目前只遇到这一个错误,祝君好运^_^

文件路径:"libressl-portable/openbsd/src/lib/libcrypto/objects/objects.txt"

错误描述:Windows: Undefined identifier X9_62_id_fieldType

参考链接:https://github.com/libressl-portable/portable/issues/131 (外链审核不过,各位手动跳转吧)

Gwani commented on 3 Nov 2015

Just for the record, in case anyone runs into the "Undefined identifier X9_62_id_fieldType" kind of problems when giving it another try with MSYS: It appears that the Perl scripts involved choke on Windows-style CRLF line endings. Make sure that the files being processed (e.g. objects.txt) all have Unix line endings (LF). This solved the problem at least for me. Note that those text files will automatically converted to CRLF line endings on checkout when having core.autocrlf=true (which is the setting recommended by Git on Windows).

vs2017(Windows平台上VS2017CMake编译LibreSSL)

d. 执行update.sh文件,更新代码及生成必要的文件

文件路径:"libressl-portable/update.sh"

由于上一步修改了 objects.txt 文件,会导致git pull失败,而且上面也手动下载了OpenBSD源码,因此这里直接注释掉脚本里的代码,跳过更新动作。

echo "pulling upstream openbsd source"if [ ! -d openbsd ]; then if [ -z "$LIBRESSL_GIT" ]; then git clone https://github.com/libressl-portable/openbsd.git // 这里下载失败了,我改用了ssh方式 else git clone $LIBRESSL_GIT/openbsd fifi// 注释掉下面这几步 ,跳过代码更新 <---- 看这里#(cd openbsd# git fetch# git checkout $openbsd_branch# git pull --rebase)

修改完后执行脚本,等待完成后,会生成ssl/VERSION, crypto/VERSION等必须的文件

./update.sh

这里也可以跳过步骤c,直接执行步骤d,遇到错误后修改 objects.txt 文件然后做一次git commit提交,再执行update.sh脚本也是可以的。

至此,准备工作就绪,接下来就是使用cmake生成工程,vs编译代码啦

e. 在visual studio控制台执行cmake生成工程文件

控制台:VS 2017的 x64_x86 交叉工具命令提示符,根据个人情况选择合适的,我这里是用x64机器编译x86版本的动态库

mkdir build // 路径:libressl-portable/buildcd build// BUILD_SHARED_LIBS默认是OFF,即编译静态库cmake -G "Visual Studio 15 2017" -DBUILD_SHARED_LIBS=ON

cmake 成功后,会有Configuring done、Generating done等信息,而且在build目录下会有LibreSSL.sln解决方案。

f. 编译工程,可以直接在控制台进行,也可以通过visual studio打开LibreSSL.sln来编译。

msbuild.exe LibreSSL.sln /p:configuration="debug" /p:platform="win32"

等待编译完,就会生成ssl、crypto、tsl动态库和openssl.exe程序。

"libressl-portable/build/crypto/Debug/crypto-49.dll""libressl-portable/build/ssl/Debug/ssl-52.dll""libressl-portable/build/tls/Debug/tls-25.dll""libressl-portable/build/apps/openssl/Debug/openssl.exe"

头文件路径在:

"libressl-portable/include/tls.h""libressl-portable/include/openssl/*"

最后,创建工程,添加相应的头文件包含路径、动态库路径及动态库后,即可正常使用。

具体可以参考 libressl-portable/tests 中的测试程序。

完。

上一篇:nba雷霆vs开拓者(西部最意外结果开拓者缺1巨头仍31领先 雷霆顽疾难除翻盘无望)
下一篇:新浪篮球直播(双色球第21103期开奖快讯红球2组同尾 蓝球15)
相关文章
返回顶部小火箭