• vcpkg 安装任意版本的开源库


    为表述方便,本文全以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
    
    • 1
    • 2
    • 3

    但是这样有个问题是,这样只能安装默认版本的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
        }
      ]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    那如何安装自己想要的版本呢? 比如目前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.

    1. Go to your git installed vcpk folder.
    2. 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
    
    • 1

    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.)

    1. Checkout the commit of interest : git checkout b1fea4588
    2. 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的工程进行改造。具体过程如下:

    1. 利用git log找到升级openssl1.1.1n的节点

    2. git show 查看具体提交了什么内容

    3. 仿照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)]

    1. install ./vcpkg install openssl:x64-windows
  • 相关阅读:
    Mac 睡眠唤醒 不睡眠 问题
    腾讯薪酬制度改革引争议:升职后不立即加薪,还有可能被降薪?
    一套轻量、安全的问卷系统基座,提供面向个人和企业的一站式产品级解决方案
    归并排序,求逆序对
    GLOG 日志宏分析与PR合并
    docker部署Jenkins与任务创建【七千字超详细指南】
    教你自己搭建一个IP池(绝对超好用!!!!)
    百度地图高级进阶开发:圆形区域周边搜索地图监听事件(覆盖物重叠显示层级\图像标注监听事件、setZIndex和setTop方法)
    Hive的基本知识与操作
    Linux常用命令——compress命令
  • 原文地址:https://blog.csdn.net/poinsettia/article/details/127905355