openssl之windows编译

文章目录

    • 一、编译前工作
    • 二、编译安装
    • 三、设置CMake的OpenSSL路径

一、编译前工作

        进入下载页面:https://www.openssl.org/source,下载.tar.gz包到指定目录。例如:下载openssl-1.1.1k.tar.gz并解压到D:\workspace\openssl-1.1.1k
        在父目录创建构建目录,例如:D:\workspace\openssl-1.1.1k-build,通过终端进入构建目录,输入命令:

  • x86
perl ..\openssl-1.1.1k\Configure VC-WIN32 no-asm --prefix=D:\openssl-1.1.1k-windows-x86-msvc
  • x64
perl ..\openssl-1.1.1k\Configure VC-WIN64A no-asm --prefix=D:\openssl-1.1.1k-windows-x64-msvc

说明: 如果要编译静态库,则需要加上选项 no-shared,默认编译动态库
如果过程中出现以下报错:

D:\software\openssl\build>perl ..\openssl-1.1.1k\Configure VC-WIN64A no-asm no-shared --prefix=D:\openssl-1.1.1k-windows-x64-msvc
Configuring OpenSSL version 1.1.1k (0x101010bfL) for VC-WIN64A
Using os-specific seed configuration
Can't locate Win32/Console.pm in @INC (you may need to install the Win32::Console module) (@INC contains: D:/software/openssl/openssl-1.1.1k/util/perl C:/Program Files/Perl64/site/lib C:/Program Files/Perl64/lib) at C:/Program Files/Perl64/site/lib/ActivePerl/Config.pm line 400.
Compilation failed in require at C:/Program Files/Perl64/site/lib/ExtUtils/MakeMaker.pm line 10.
BEGIN failed--compilation aborted at C:/Program Files/Perl64/site/lib/ExtUtils/MakeMaker.pm line 10.
Compilation failed in require at C:/Program Files/Perl64/site/lib/IPC/Cmd.pm line 235.

则需要修改perl对应目录的文件(如:C:/Program Files/Perl64/site/lib/ActivePerl/Config.pm),定位到400行所在的函数(本机为:sub _warn),把该函数内的逻辑注释掉即可。

二、编译安装

        配置成功后,打开Visual Sutdio的开发人员命令窗口(注意: 否则如果在普通的命令窗口在配置时,会提示:'nmake' 不是内部或外部命令,也不是可运行的程序 或批处理文件)。

  • x86
    openssl之windows编译_第1张图片
    openssl之windows编译_第2张图片

  • x64
    openssl之windows编译_第3张图片
    openssl之windows编译_第4张图片
            进入构建目录,例如:D:\workspace\openssl-1.1.1k-build,输入编译命令:nmake,成功后输入测试命令:nmake test,最后输入安装命令:nmake install,即可把openssl库安装到目录:D:\openssl-1.1.1k-windows-x86-msvcD:\openssl-1.1.1k-windows-x64-msvc

三、设置CMake的OpenSSL路径

        使用CMake构建其他库时,如果需要依赖于OpenSSL,则需要配置环境变量OPENSSL_ROOT_DIR,这样才能找到OpenSSL的头文件和库,例如:
openssl之windows编译_第5张图片

你可能感兴趣的:(算法,windows)