Windows 编译 libcurl with openssl 的链接问题

libcurl 7.52.0 编译 OpenSSL 依赖。

1.使用如下目录结构

1
2
3
4
5
6
7
8
somedirectory\
|_curl-src
| |_winbuild
|
|_deps
|_ lib
|_ include
|_ bin

2.将 OpenSSL 的 lib,dll,头文件(带openssl文件夹) 分别拷贝到 deps 路径的 lib,bin,include 目录下

  1. 进入 winbuild 目录。
1
nmake /f Makefile.vc mode=dll  WITH_SSL=dll  ENABLE_WINSSL=no

编译正确。但是在链接阶段出现 openssl.obj 中的某些符号无法链接:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
openssl.obj : error LNK2019: 无法解析的外部符号 _OpenSSL_version_num,该符号在函数 _Curl_ossl_version 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _EVP_PKEY_get0_RSA,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _EVP_PKEY_get0_DSA,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _EVP_PKEY_get0_DH,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _RSA_get0_key,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _RSA_get0_factors,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _RSA_get0_crt_params,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _DH_get0_pqg,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _DH_get0_key,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _DSA_get0_pqg,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _DSA_get0_key,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _X509_get_version,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _X509_get_X509_PUBKEY,该符号在函数 _pkp_pin_peer_pubkey 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _X509_get0_extensions,该符号在函数 _get_cert_chain 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _SSL_CTX_set_options,该符号在函数 _ossl_connect_step1 中被引用
openssl.obj : error LNK2019: 无法解析的外部符号 _TLS_client_method,该符号在函数 _ossl_connect_step1 中被引用

检查 libcurl\lib\vtls\openssl.c 文件,发现这些符号都与 **OPENSSL_VERSION_NUMBER **宏有关。这个宏在 openssl的头文件 opensslv.h 中定义。

在 libcurl\lib\vtls\openssl.h 中添加 opensslv.h 引用,重新编译,可解决此问题。