【问题标题】:How to link OpenSSL libraries statically in VS2019?如何在 VS2019 中静态链接 OpenSSL 库?
【发布时间】:2020-11-17 09:15:27
【问题描述】:

我想在 VC++ 项目中使用OpenSSL。但我不能静态链接库。先说说我是怎么做到的吧。

1、下载openssl-1.1.1h.tar.gz并解压到“d:\openssl\sources\openssl-1.1.1h”

2、在Visual Studio 2019 Tools Command Prompt中构建OpenSSL

构建成功后,我在 "d:\openssl\builds\openssl-1.1.1h-VC-WIN32" 中找到了 4 个目录

并且“d:\openssl\builds\openssl-1.1.1h-VC-WIN32\lib”中有两个库

3、在VS2019中创建一个空的VC++项目

4、添加Program.cpp并在Program.cpp中添加代码

5、根据How to add static libraries to a Visual studio project添加静态库

6,调试然后我遇到了错误

为什么要查找“libssl-1_1.dll”?我静态链接了“libssl.lib”!我找不到原因,请帮帮我!

如果我将其配置为“无共享”,我遇到了“致命错误 LNK1120:28 个未解决的外部”

根据Unresolved symbols when built statically for Visual Studio,这个问题可以通过添加以下代码来解决

#pragma comment(lib, "crypt32")
#pragma comment(lib, "ws2_32.lib")

可以根据Add dependencies for "ws2_32.lib" and "crypt32.lib"解决

【问题讨论】:

    标签: visual-studio visual-c++ static openssl


    【解决方案1】:

    在默认构建中创建的 .lib 文件只是调用 dll 的存根。

    在构建 OpenSSL 时,您需要指定要为静态链接构建它。

    修改用于在末尾添加“no-shared”的“配置”行,例如

    perl Configure --prefix=d:\your\prefix\here VC-WIN32 no-shared
    

    然后你需要重建 OpenSSL:

    nmake clean
    nmake
    nmake test
    nmake install
    

    【讨论】:

      猜你喜欢
      • 2016-05-30
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      • 1970-01-01
      • 2017-08-22
      相关资源
      最近更新 更多