用vcpkg安装openssl

本文介绍了如何在Rust开发中解决因缺失OpenSSL依赖导致的编译问题,步骤包括安装vcpkg、配置环境变量以及重新编译。作者详细描述了使用vcpkg下载并安装openssl,以及设置必要的环境变量以确保编译过程顺利进行。
摘要由CSDN通过智能技术生成

背景

最近学习Rust的时候,有个依赖需要用到Openssl,但是cargo编译的时候提示如下信息:

Caused by:
  process didn't exit successfully: `D:\xxx\target\debug\build\openssl-sys-985d7667cb187e06\build-script-main` (exit code: 101)
  --- stdout
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR
  X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR
  X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR
  X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  note: vcpkg did not find openssl: Could not find Vcpkg tree: No vcpkg installation found. Set the VCPKG_ROOT environment variable or run 'vcpkg integrate install'

  --- stderr
  thread 'main' panicked at C:\xxx\.cargo\registry\src\index.crates.io-6f17d22bba15001f\openssl-sys-0.9.98\build\find_normal.rs:190:5:

  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = x86_64-pc-windows-msvc
  $TARGET = x86_64-pc-windows-msvc
  openssl-sys = 0.9.98

  It looks like you're compiling for MSVC but we couldn't detect an OpenSSL
  installation. If there isn't one installed then you can try the rust-openssl
  README for more information about how to download precompiled binaries of
  OpenSSL:

  https://github.com/sfackler/rust-openssl#windows

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

解决方案

1 安装vcpkg

1.1 下载代码组件

用git clone代码或者下载对应的代码zip包

git clone https://github.com/microsoft/vcpkg
1.1 生成vcpkg.exe

执行初始化脚本

.\vcpkg\bootstrap-vcpkg.bat

其他安装命令可以查看 .\vcpkg\README_zh_CN.md

1.2 安装openssl
.\vcpkg\vcpkg install openssl:x64-windows

安装后的文件在.\vcpkg\packages

2 配置环境变量

配置环境变量

X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR =  安装目录\vcpkg\packages\openssl_x64-windows\lib
X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR = 安装目录\vcpkg\packages\openssl_x64-windows\include
X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR = 安装目录\vcpkg\packages\openssl_x64-windows

在这里插入图片描述

3 重新编译运行,正常通过

cargo run

在这里插入图片描述

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值