为表述方便,本文全以
openssl
为例。
常规安装
前面已经写过vcpkg的简明教程:https://blog.csdn.net/poinsettia/article/details/127885576
只要执行以下几行命令,就可以安装好openssl
git clone https://github.com/Microsoft/vcpkg.git # install vcpkg./vcpkg\bootstrap-vcpkg.bat # build vcpkg.exe./vcpkg install openssl:x64-windows # install opensl
但是这样有个问题是,这样只能安装默认版本的openssl,无法指定具体的openssl。
注:openssl的版本定义在ports文件夹中的vcpkg.json中
Example
{"name":"openssl","version-string":"1.1.1n","description":"OpenSSL is an open source project that provides a robust, commercial-grade, and full-featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. It is also a general-purpose cryptography library.","homepage":"https://www.openssl.org","license":"OpenSSL","dependencies":[{"name":"vcpkg-cmake","host":true},{"name":"vcpkg-cmake-config","host":true}]}
那如何安装自己想要的版本呢? 比如目前vcpkg的默认版本(其实是最新版本)是3.0.7,我想安装1.1.1n 怎么办呢?
安装任意版本
Refer:https://stackoverflow.com/questions/53805917/install-older-version-of-protobuf-via-vcpkg
The selected answer
To have a specific version of a package in
vcpkg
, you need to checkout at the appropriate point in time in the vcpk repo.
- Go to your git installed
vcpk
folder. - Identify the commit matching the version of
protobuf
you’re looking for.
The following line color-codes the commit history to make it more readable and pipe it with
grep
to identify
protobuf
related commits.
git log --color=always --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad)' --date=short | grep --color=never openssl
You’ll find a line like
b1fea4588 - [protobuf] update to 3.5.1 (2018-01-31)
. (The commit hash/message may have changed if the history has been rewritten.)
- Checkout the commit of interest :
git checkout b1fea4588
- Run
vcpkg install protobuf
The issue of package version management is very active on
vcpkg
repo. Check Issue #3592
大意就是根据git log 找到openssl1.1.1n 对应的vcpkg的git 节点,把vcpkg git repo reset到对应节点,然后就可以install 1.1.1n版本啦。
那如果版本在vcpkg找不到呢? 比如 openssl1.1.1q
利用vcpkg build自己想要的包
refer:https://vcpkg.io/en/docs/examples/packaging-zipfiles.html
文中的方法麻烦的点是在于要自己写
portfile.cmake
, 为了简单起见,我直接利用了openssl1.1.1n的工程进行改造。具体过程如下:
- 利用git log找到升级openssl1.1.1n的节点
- git show 查看具体提交了什么内容
- 仿照git show提交的内容,把1.1.1n版本改为1.1.1q版本。我是借助TortoiseSVN 工具,可以更方便看到修改的文件。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CFt4blZy-1668671164163)(windows openssl 出包.assets/image-20221117154016692.png)]
遇到的最主要问题就是hash值校验,这个问题也可以很方便解决,因为在install 的时候会给出提示,提示中有正确的hash,直接复制过去即可。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cV9iUKyX-1668671164164)(windows openssl 出包.assets/image-20221117154407120.png)]
- install
./vcpkg install openssl:x64-windows
版权归原作者 poinsettia 所有, 如有侵权,请联系我们删除。