如何在 VS2019 中静态 link OpenSSL 库?
How to link OpenSSL libraries statically in VS2019?
我想在 VC++ 项目中使用 OpenSSL。但我不能静态 link 库。先说说我是怎么做到的吧
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”?我 link 静态编辑了“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"
解决
在默认构建中创建的 .lib 文件只是调用 dll 的存根。
构建 OpenSSL 时,您需要指定要为静态链接构建它。
修改您用来在末尾添加“no-shared”的“Configure”行,例如
perl Configure --prefix=d:\your\prefix\here VC-WIN32 no-shared
然后您将需要重建 OpenSSL:
nmake clean
nmake
nmake test
nmake install
我想在 VC++ 项目中使用 OpenSSL。但我不能静态 link 库。先说说我是怎么做到的吧
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”?我 link 静态编辑了“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"
解决在默认构建中创建的 .lib 文件只是调用 dll 的存根。
构建 OpenSSL 时,您需要指定要为静态链接构建它。
修改您用来在末尾添加“no-shared”的“Configure”行,例如
perl Configure --prefix=d:\your\prefix\here VC-WIN32 no-shared
然后您将需要重建 OpenSSL:
nmake clean
nmake
nmake test
nmake install