在 Visual Studio 2012 中使用 OpenSSL

2022-01-07 00:00:00 openssl md5 sha c++ visual-studio-2012

我已经从 http://www.openssl.org/source/下载了最新版本的 Openssl

我想在 Visual Studio 2012 中使用它,尤其是获取文件的 md5/sha-1 哈希,但我无法使用 openssl 库包含/设置环境.老实说,我对要包含的内容和位置感到困惑,但我已经阅读了 README-s.

I would like to use it in Visual Studio 2012, especially getting the md5/sha-1 hash of a file, but I can not include / setup the environment with the openssl library. To be honest I got confused what to include, and where, however I have read the README-s.

我收到此错误.

Error   1   error LNK2019: unresolved external symbol _MD5_Init referenced in function _main

所以我的问题是,我已经下载了最新版本(openssl-1.0.1e.tar.gz),我应该在 VS2012 中配置什么才能使用 lib?谢谢!

So my question is, I have downloaded the latest release (openssl-1.0.1e.tar.gz), what should I config in VS2012 to be able to use the lib? Thanks!

更新

这个问题也帮助我找到了解决方案.使用 Visual Studio 2010 和 OpenSSL 提升 SSL

This question helped me also in finding the solution. Boost SSL with Visual Studio 2010 and OpenSSL

在 VS2012 中使用 openSSL 库所需的步骤:

The steps required to use the openSSL lib with VS2012:

  • 从 http://下载并安装一个版本(我有 64 位操作系统,但我安装了 32 位 openssl)/slproweb.com/products/Win32OpenSSL.html.
  • 在VS中新建项目,然后配置属性/C/C++/General/Additional Include Directories: openssl include folder (C:OpenSSL-Win32include)
  • 链接器/通用/附加库目录:C:OpenSSL-Win32lib
  • 链接器/输入/附加依赖项:

libeay32.lib libeay32MTd.lib libeay32MT.lib libeay32MDd.liblibeay32MD.lib ssleay32.lib ssleay32MTd.lib ssleay32MT.libssleay32MDd.lib ssleay32MD.lib

libeay32.lib libeay32MTd.lib libeay32MT.lib libeay32MDd.lib libeay32MD.lib ssleay32.lib ssleay32MTd.lib ssleay32MT.lib ssleay32MDd.lib ssleay32MD.lib

(据说我只需要添加与 C/C++/代码生成/运行时库匹配的那个,但它是这样工作的.)

(It was written that I need to only add that one which matches with C/C++/Code Generation/Runtime Library, but It works me this way.)

  • 将这些文件复制到当前 VS 文件夹/VC/lib 中

推荐答案

你用什么编译器来编译 OpenSSL?你用过MinGW吗?如果是这样,请确保不要剥离它们(或仅使用 --strip-unneeded),否则导入符号将被剥离.标头和 lib 版本是否匹配?

What compiler did you use to compile OpenSSL? Did you use MinGW? If so, make sure you don't strip them (or just with --strip-unneeded) otherwise import symbols will be stripped. Do the header and lib version match?

也许您想尝试以下预构建的:http://slproweb.com/products/Win32OpenSSL.html 那些肯定有效.

Maybe you want to try pre built ones from: http://slproweb.com/products/Win32OpenSSL.html those work for sure.

相关文章