visual-studio 包含 OpenSSL 作为静态库,但它仍在寻找 DLL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4074176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 12:40:14  来源:igfitidea点击:

Included OpenSSL as a static library, but it's still looking for a DLL?

visual-studiodllopensslstatic-libraries

提问by mindthief

I installed OpenSSL 1.0.0 on Windows using the installer available at: http://www.slproweb.com/products/Win32OpenSSL.html

我使用以下提供的安装程序在 Windows 上安装了 OpenSSL 1.0.0:http: //www.slproweb.com/products/Win32OpenSSL.html

I added the .lib files to my project (this is Visual Studio, added it to Project Settings->Linker->Input), and it compiles and works fine. But when I remove the OpenSSL DLL files in Windows\system32, it complains that

我将 .lib 文件添加到我的项目(这是 Visual Studio,将它添加到项目设置->链接器->输入),并且它编译并运行良好。但是当我删除 Windows\system32 中的 OpenSSL DLL 文件时,它抱怨说

"Debugger:: An unhandled non-continuable STATUS_DLL_NOT_FOUND exception was thrown during process load"

Any idea why it's still looking for the DLL even when it's compiled with the static libs? I'm not referencing the DLLs anywhere in the project. The static libs I included are libeay32.lib and ssleay32.lib.

知道为什么它仍然在寻找 DLL,即使它是用静态库编译的吗?我没有在项目中的任何地方引用 DLL。我包含的静态库是 libeay32.lib 和 ssleay32.lib。

Thanks, -M

谢谢,-M

采纳答案by Adam Rosenfield

It's looking for the DLLs because the code is loaded dynamically at runtime. The code in the static libraries is just a set of stub functions which call into the DLL -- compare the sizes of the .lib and .dll files, and I bet you'll see that the DLLs are much larger, since that's where the bulk of the actual encryption code lies.

它正在寻找 DLL,因为代码是在运行时动态加载的。静态库中的代码只是一组调用 DLL 的存根函数——比较 .lib 和 .dll 文件的大小,我敢打赌你会看到 DLL 更大,因为那是大部分实际的加密代码都是谎言。

Hence, as you found out, you should not delete the DLLs. In order to distribute your program properly, you'll also need to distribute those DLLs with it in order for it to work correctly. However, keep in mind that there are legal issues with doing this, since there are US export restrictions on certain encryption code. So be extra careful in redistributing those DLLs -- make extra sure what you're doing is legal.

因此,正如您所发现的,您不应删除 DLL。为了正确分发您的程序,您还需要将这些 DLL 与它一起分发以使其正常工作。但是,请记住,这样做存在法律问题,因为美国对某些加密代码有出口限制。 因此在重新分发这些 DLL 时要格外小心——确保您所做的工作是合法的

回答by ms vt

use libeay32MT.lib file that have almost 19 mb size as your library. because it is a static library but libeay32.lib is a library for using the dll.

使用几乎 19 mb 大小的 libeay32MT.lib 文件作为您的库。因为它是一个静态库,而 libeay32.lib 是一个用于使用 dll 的库。

回答by Arash

You can get static libraries here:

您可以在此处获取静态库:

http://www.ie7pro.com/openssl/openssl-0.9.8g_static_win32.zip

http://www.ie7pro.com/openssl/openssl-0.9.8g_static_win32.zip

(see http://www.ie7pro.com/openssl.html).

(参见http://www.ie7pro.com/openssl.html)。

These are built with static runtime libraries so if you are using VC++ you may need to go to:

这些是使用静态运行时库构建的,因此如果您使用 VC++,您可能需要访问:

Configuration Properties--> C/C++--> Code Generation--> Runtime Library

配置属性--> C/C++--> 代码生成--> 运行时库

and select /MT instead of /MD to avoid linkage conflicts (or alternatively use the /NODEFAULTLIB:LIBCMT, etc. in Linker--> Command Line--> Additional Options).

并选择 /MT 而不是 /MD 以避免链接冲突(或者在 Linker--> Command Line--> Additional Options 中使用 /NODEFAULTLIB:LIBCMT 等)。