VS2017编译POCO带OPENSSL的64位动态库

本文详细介绍了在Windows环境下使用VS2017编译openssl和Poco库的过程,包括所需编译环境配置、编译步骤及解决常见问题的方法。

承接Qt/C++软件开发项目,高质量交付,灵活沟通,长期维护支持。需求所寻,技术正适,共创完美,欢迎私信联系!

一、编译环境

  • windows10 64位

二、编译软件

三、开源代码

四、openssl 编译

  1. 安装 ActivePerl 软件,打开ActivePerl_x64_5.24.1.2402.exe软件,接着按照正常软件安装即可;
  2. 开始 -> Visual Studio 2017 -> 选择64位编译工具 -> 管理员权限打开,如下图

在这里插入图片描述

  1. 工具切换到 openssl 目录,比如我的是 E:\prj_vs\openssl-1.1.1g ,如下图:

在这里插入图片描述

  1. 在openssl 目录下创建一个要存放最终的输出的文件夹,比如我的是build_release64,然后执行命令:perl Configure VC-WIN64A no-asm --prefix=“E:\prj_vs\openssl-1.1.1g\build_release64”,执行中可能会提示你nmake不存在的警告,忽略它,效果如下
E:\prj_vs\openssl-1.1.1g>perl Configure VC-WIN64A no-asm --prefix="E:\\prj_vs\\openssl-1.1.1g\\build_release64"
Configuring OpenSSL version 1.1.1g (0x1010107fL) for VC-WIN64A
Using os-specific seed configuration

It looks like you don't have either nmake.exe or dmake.exe on your PATH,
so you will not be able to execute the commands from a Makefile.  You can
install dmake.exe with the Perl Package Manager by running:

    ppm install dmake

Creating configdata.pm
Creating makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   Troubleshooting section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************
  1. nmake
  2. nmake test
E:\prj_vs\openssl-1.1.1g>nmake test

Microsoft (R) 程序维护实用工具 14.16.27043.0 版
版权所有 (C) Microsoft Corporation。  保留所有权利。

        D:\software\vs2017\VSIDE\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe /                   depend && D:\software\vs2017\VSIDE\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe /                   _tests

Microsoft (R) 程序维护实用工具 14.16.27043.0 版
版权所有 (C) Microsoft Corporation。  保留所有权利。


Microsoft (R) 程序维护实用工具 14.16.27043.0 版
版权所有 (C) Microsoft Corporation。  保留所有权利。

        mkdir .\test\test-runs
        set SRCTOP=.
        set BLDTOP=.
        set RESULT_D=.\test\test-runs
        set PERL=D:\software\Perl64\bin\perl.exe
        set OPENSSL_ENGINES=E:\prj_vs\openssl-1.1.1g\engines
        set OPENSSL_DEBUG_MEMORY=on
        "D:\software\Perl64\bin\perl.exe" ".\test\run_tests.pl"
test\recipes\01-test_abort.t .................... ok
test\recipes\01-test_sanity.t ................... ok
test\recipes\01-test_symbol_presence.t .......... ok
....
....
test\recipes\90-test_v3name.t ................... ok
test\recipes\95-test_external_boringssl.t ....... skipped: No external tests in this configuration
test\recipes\95-test_external_krb5.t ............ skipped: No external tests in this configuration
test\recipes\95-test_external_pyca.t ............ skipped: No external tests in this configuration
test\recipes\99-test_ecstress.t ................. ok
test\recipes\99-test_fuzz.t ..................... ok
All tests successful.
Files=155, Tests=1375, 398 wallclock secs ( 1.36 usr +  0.16 sys =  1.52 CPU)
Result: PASS
  1. nmake install,最终在build_release64文件夹下生成如下内容

在这里插入图片描述

五、openssl 编译时遇到的坑

  • 开始安装的是 ActivePerl-5.28.msi 版本的,安装过程一直卡着不动,最后放弃安装;
  • 接着换着安装 ActivePerl-5.26.msi 版本的,安装过程也很久,但好歹安装成功了;然而执行perl命令编译 openssl 时遇到了如下错误,按照网上方法解决该错误,perl 命令也成功了,然而在执行nmake test 命令时却卡住了,最终不得不放弃该版本;

第一次错误:
Can’t locate Win32/Console.pm in @INC (you may need to install the Win32::Console module) (@INC contains: E:/prj_vs/openssl-1.1.1g/util/perl D:/software/Perl64/site/lib D:/software/Perl64/lib) at D:/software/Perl64/lib/ActivePerl/Config.pm line 400.

第一次错误解决方式,在Config.pm line 400处,屏蔽部分功能:

# Prevent calling Win32::Console::DESTROY on a STDOUT handle
#my $console;
sub _warn {
#    my($msg) = @_;
#    unless (-t STDOUT) {
#	print "\n$msg\n";
#	return;
#   }
#    require Win32::Console;
#    unless ($console) {
#	$console = Win32::Console->new(Win32::Console::STD_OUTPUT_HANDLE());
#    }
#    my($col,undef) = $console->Size;
#    print "\n";
#    my $attr = $console->Attr;
#    $console->Attr($Win32::Console::FG_RED | $Win32::Console::BG_WHITE);
#    for (split(/\n/, "$msg")) {
#	$_ .= " " while length() < $col-1;
#	print "$_\n";
#    }
#    $console->Attr($attr);
#    print "\n";
}

第二次错误:
test\recipes\60-test_x509_time.t … ok
test\recipes\70-test_asyncio.t … ok
test\recipes\70-test_bad_dtls.t … ok
test\recipes\70-test_clienthello.t … ok
test\recipes\70-test_comp.t …

六、编译Poco库

  1. 打开目录下 buildwin.cmd 文件,文件开头补充前面编译生成的openssl 动态库相关资源,操作如下:
rem openssl
set OPENSSL_DIR=E:\prj_vs\openssl-1.1.1g\build_release64
set OPENSSL_INCLUDE=%OPENSSL_DIR%\include;%OPENSSL_DIR%\include\openssl
set OPENSSL_LIB=%OPENSSL_DIR%\lib;%OPENSSL_DIR%\lib\engines-1_1
set INCLUDE=%INCLUDE%;%OPENSSL_INCLUDE%
set LIB=%LIB%;%OPENSSL_LIB%

在这里插入图片描述

  1. 拷贝build_vs150.cmd文件,并把内容改为 buildwin 150 build shared both x64 nosamples notests ,如下图:

在这里插入图片描述

  1. 双击执行 build_vs150x64.cmd,最终会在当前目录生成 bin64、lib64 两个文件夹,如下:

在这里插入图片描述
在这里插入图片描述

七、结论

整体来说,编译这两个库,基本耗时在下载软件、下载开源代码、踩坑的过程…

评论 7
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值