如何在Visual Studio中包括OpenSSL

编程入门 行业动态 更新时间:2024-10-21 15:55:55
本文介绍了如何在Visual Studio中包括OpenSSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我很难尝试将openssl添加到我的项目中.我已经下载了用于Windows的预编译安装程序,并且已经安装了库,但是找不到在项目中包含openssl的方法.

I am having a hard time trying to add openssl to my project. I have downloaded the precompiled installer for windows, and I have the libraries installed, but I can't find a way to include openssl in my project.

注意:我在Windows 7 x64上使用Visual Studio Expres 2012,但不限于该环境.

Note: I am using Visual Studio Expres 2012 on Windows 7 x64, but it's not restricted to that environment.

推荐答案

简介

  • 问题/答案基于:

    Intro

    • Although the question / answer is based on:

      • OpenSSL 1.0.1 *
      • VStudio 2012
      • OpenSSL 1.0.1*
      • VStudio 2012

      它适用于任何 OpenSSL 版本( v.0.9.* , v1.0.* , v1.1.* , v3.0 )和任何 VStudio 版本( v2005 +)

      it applies to any OpenSSL version (v.0.9.*, v1.0.*, v1.1.*, v3.0), and any VStudio version (v2005+)

      OpenSSL 构建也可以在 [GitHub]:CristiFati/Prebuilt-Binaries-(主)Prebuilt-Binaries/OpenSSL

      OpenSSL builds are also available at [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/OpenSSL

      假设您已在 dir 中安装了 OpenSSL ,例如:"C:\ Program Files \ Openssl-Win32-1.0.1p ..... "(或其他任何名称);我将其称为 OPENSSL_INSTALL_DIR (因为它是一个环境变量).因此,%OPENSSL_INSTALL_DIR%应该包含一堆 dir 和文件,对于我们来说,这与它们无关:

      Let's assume you have installed OpenSSL in a dir like: "C:\Program Files\Openssl-Win32-1.0.1p....." (or whatever other name); I am going to refer to that as OPENSSL_INSTALL_DIR (as it was an env var). So %OPENSSL_INSTALL_DIR% should contain a bunch of dirs and files, out of which matter for us:

      • Dirs:

      • Dirs:

      • 包括
      • lib
      • include
      • lib

      文件(由于它们的名称因版本而异,我将使用( Nix 样式 var )占位符来引用它们;也可能位于在 bin subdir 中):

      Files (since their names vary across versions, I'm going to refer to them using (Nix style var) placeholders; also they might be located in a bin subdir):

      • $ {LIBCRYPTO} .dll
      • $ {LIBSSL} .dll
      • ${LIBCRYPTO}.dll
      • ${LIBSSL}.dll

      其中 LIBCRYPTO (#1.)和 LIBSSL (#2.)定义如下:

      where LIBCRYPTO (#1.) and LIBSSL (#2.) are defined as follows:

      • v1.0.2 及更低版本

    • libeay32
    • ssleay32 (也可以复制(或 symlink ed)到 libssl32 )
    • libeay32
    • ssleay32 (might be also copied (or symlinked) to libssl32)
    • v1.1.*

    • libcrypto-1 _ *(-x64)
    • libssl-1 _ *(-x64)
    • libcrypto-1_*(-x64)
    • libssl-1_*(-x64)
    • v3.0

    • libcrypto-3 *
    • libssl-3 *
    • libcrypto-3*
    • libssl-3*
    • 要利用它,在您的 VStudio 项目中,您必须:

      In order to make use of it, in your VStudio project you have to:

      配置编译器( [MS.Docs]:按字母顺序列出的编译器选项)请教:

      • 在此处搜索包含(标头( .h ))文件.转到"项目属性-> C/C ++->常规->其他包含目录",然后添加 %OPENSSL_INSTALL_DIR%\ include (如果您需要添加其他路径,并用分号( ; )隔开.现在,您可以在源代码中包含 OpenSSL 头文件. 请注意,因为"%OPENSSL_INSTALL_DIR%\ include " dir 包含一个 openssl 子目录,并且该子目录下是实际的头文件,所以您的 #include 子句必须看起来像这样:

      • Where to search for include (header (.h)) files. Go to your "Project Properties -> C/C++ -> General -> Additional Include Directories" and adding %OPENSSL_INSTALL_DIR%\include (if you need to add other paths, separate them by a semicolon (;)). Now you can include in your source code OpenSSL header files. Note that because "%OPENSSL_INSTALL_DIR%\include" dir contains an openssl subdir and under that subdir are the actual header files, your #include clauses would have to look like this:

      #include <openssl/ssl.h>

      您当然可以在项目中添加%OPENSSL_INSTALL_DIR%\ include \ openssl dir ,然后上面的include语句将是:

      Of course you could add %OPENSSL_INSTALL_DIR%\include\openssl dir to your project, and then the above include statement would be:

      #include <ssl.h>

      但建议使用前者(推荐)

      but the former is preferred (recommended)

      配置链接器( [MS.Docs]:链接器选项)请教:

      • 在此处搜索图书馆.为此,请转到"项目属性->链接器->常规->其他库目录",然后添加 %OPENSSL_INSTALL_DIR%\ lib >(同样,如果有多个路径,请用 ; 隔开)

      • Where to search for libraries. You can do that by going to your "Project Properties -> Linker -> General -> Additional Library Directories" and adding %OPENSSL_INSTALL_DIR%\lib (again, if there are multiple paths, separate them by ;)

      要使用的库. "%OPENSSL_INSTALL_DIR%\ lib " dir 包含一堆 .lib 文件.其中,您(最有可能)仅需要 $ {LIBCRYPTO} .lib 和/或 $ {LIBSSL} .lib .转到"项目属性->链接器->输入->其他依赖项",然后将这2个库添加到现有库的旁边

      What libraries to use. "%OPENSSL_INSTALL_DIR%\lib" dir contains a bunch of .lib files. Out of those, you will (most likely) only need ${LIBCRYPTO}.lib and / or ${LIBSSL}.lib. Go to your "Project Properties -> Linker -> Input -> Additional Dependencies" and add those 2 libraries next to the existing ones

      现在,如果所有设置和源代码正确,那么您应该有一个可构建"项目.当您要运行您的项目输出(另一个可执行文件所需的 .exe 或 .dll )时,我不在这里讨论如果您使用的是 static lib s),则可执行文件将需要找到我在开始时提到的2个 .dll .为此,您应该任一:

      Now, if all your settings and source code are correct, you should have a "buildable" project. When you'll want to run your project output (either an .exe or a .dll needed by another executable, I am not discussing here the possibility of you are using the static libs), the executable will need to find the 2 .dlls that I mentioned at the beginning. For that, you should either:

      • 将它们复制到可执行文件所在的文件夹中( [MS.Docs]:动态链接库搜索顺序)

      将它们从%PATH% env var

      将其 dir 添加到您的%PATH% var 中. 某些安装程序可能会将2个 .dll 复制到您的"%SystemRoot%\ System32 " dir 中,在这种情况下,不再需要(我发现这种在系统 dir 中复制内容的做法是一种不好的做法,因为在我们当前的示例中,多个版本可以附带相同的文件名,而安装的最后一个会覆盖所有其他文件名)

      Add their dir to your %PATH% var. Some installers might copy the 2 .dlls in your "%SystemRoot%\System32" dir, and in that case this will no longer be necessary (I find this practice of copying stuff in system dirs a bad one, as in our current example multiple versions can ship the same file names, and the last one installed would overwrite all the others)

      重要提示:将项目定位为 32bit 或 64bit (将 Platform 设置为< VStudio IDE 中的em> Win32 或 x64 )-必须与您的 OpenSSL 安装体系结构匹配.

      Important note: Must be careful when targeting your project for 32bit or 64bit (setting Platform to Win32 or x64 in VStudio IDE) - that has to match your OpenSSL installation architecture.

更多推荐

如何在Visual Studio中包括OpenSSL

本文发布于:2023-11-13 14:36:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584593.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Visual   OpenSSL   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!