编译libcurl支持ssl

使用vs2017编译libcurl和openssl静态库。
因为用到了https相关操作所以需要libcurl支持ssh,在编译openssl的过程中遇到些小麻烦,所以记录下来。
openssl1.1.x有了些变化,附带的帮助文件,信息量不小,时间有限,暂时使用openssl1.0.x来编译。

编译好的库
http://slproweb.com/products/Win32OpenSSL.html

编译libcurl with ssh support for vs2017

下载libcrul
下载libssh2
下载openssl
下载activePerl
下载nasm

需要引入的库文件:
crypt32.lib;ws2_32.lib;wldap32.lib

  1. 安装perl
    ActivePerl-5.26.3.2603-MSWin32-x64-a95bce075
perl -version
  1. 安装nasm:设置环境变量,添加nasm的路径

  2. 编译openssl

使用vs2010的命令行

1.1.xx的变化很大,下面编译成功,但是应用链接的时候有错误信息

vs2017 command
NOTES.PERL提到需要下面的,因为之前装过CPAN所以不知道是否已经安装了,编译的时候没提示出错。
cpan -i Text::Template

perl Configure VC-WIN32 --prefix=C:\project2017\openssl_lib
perl Configure VC-WIN32 --prefix=C:\project2017\openssl_lib_debug
perl Configure no-shared debug-VC-WIN32 --prefix=C:\project2017\openssl_lib_debug
perl Configure no-shared VC-WIN32 --prefix=C:\project2017\openssl_lib_release

nmake
nmake test
nmake install
1.0.2l 版本编译

Building the 32-bit static libraries

perl Configure VC-WIN32 no-shared --prefix=C:\project\libcurl_bindproject\openssl_lib_release_1.0

perl Configure debug-VC-WIN32 no-shared no-asm --prefix=C:\project\libcurl_bindproject\openssl_lib_debug_1.0

Building the 32-bit dynamic libraries
perl Configure debug-VC-WIN32 --prefix=C:\project\libcurl_bindproject\openssl_lib_debug_1.0
perl Configure VC-WIN32 --prefix=C:\project\libcurl_bindproject\openssl_lib_debug_1.0


如果支持汇编使用这个
ms\do_nasm
不支持汇编使用这个
ms\do_ms
nmake -f ms\nt.mak
nmake –f ms\nt.mak test
nmake -f ms\nt.mak install

Configure 后面的选项可选值有 VC-WIN32(32位) | VC-WIN64A(64位AMD) | VC-WIN64I(64位Intel) | VC-CE(Windows CE)
Debug库使用这个选项debug-VC-WIN32
prefix: 表示生成的lib文件存放路径

执行完成上面的三个步骤之后在C:\project2017\openssl_lib这个目录下面会生成四个文件夹(include/lib/bin/html):

include目录下面存放的是头文件
lib目录是生成的静态库文件,文件的后缀是.lib
bin目录下面存放的是dll文件和exe文件
html目录下面存放的是文档

  1. 编译libssh2
    版本1.8.0
    添加openssl的库libeay32.lib;ssleay32.lib和头文件路径
    使用vs2017编译即可生成libssh2d.lib

  2. 编译libcurl
    curl-7.64.0

把openssl的include目录拷贝到libcurl的include目录里面
使用vs2017编译
添加libssh2的include,项目里面添加libssh2d.lib引用

如果有下面的问题 添加 crypt32.lib 库

Error LNK2019 unresolved external symbol __imp__CertOpenStore@20 referenced in function _capi_open_store libssh2 Error LNK2019 unresolved external symbol __imp__CertCloseStore@8 referenced in function _capi_find_key libssh2 Error LNK2019 unresolved external symbol __imp__CertEnumCertificatesInStore@8 referenced in function _capi_find_cert libssh2 Error LNK2019 unresolved external symbol __imp__CertFindCertificateInStore@24 referenced in function _capi_find_cert libssh2 Error LNK2019 unresolved external symbol __imp__CertFreeCertificateContext@4 referenced in function _capi_rsa_free libssh2 Error LNK2019 unresolved external symbol __imp__CertDuplicateCertificateContext@4 referenced in function _capi_load_ssl_client_cert libssh2 Error LNK2019 unresolved external symbol __imp__CertGetCertificateContextProperty@16 referenced in function _capi_cert_get_fname libssh2

添加预编译信息
CURL_STATICLIB;USE_LIBSSH2;CURL_DISABLE_LDAP;HAVE_LIBSSH2;HAVE_LIBSSH2_H;LIBSSH2_WIN32;LIBSSH2_LIBRARY

  1. 使用libcurl
    #pragma comment(lib,"Wldap32.lib")
    #pragma comment(lib,"Ws2_32.lib")
    #pragma comment(lib,"crypt32.lib")


    #ifdef _DEBUG
    #pragma comment(lib,"libcurld.lib")
    #else
    #pragma comment(lib,"libcurl.lib")
    #endif