Introduction

If you do any sort of C++ development on Windows, then you know that library/package management can be quite a pain at times (ever built OpenCV from source? How about boost?). There has never really been a good package manager on windows like what you would find on linux (i.e. pacman); but now there is vcpkg!

So what makes vcpkg great? Well it’s basically a low key package manager for Windows and best of all, it’s built by Microsoft and is open source. Yes you read that right, a Microsoft owned repo that is open source! They’ve been doing that a lot lately actually.

How to Use It?

Follow the instructions in the readme of the vcpkg Github repo to get started. You basically just clone the repo and then run a .batfile that installs and builds the vcpkg executable. You can now install packages which will be automatically downloaded and builtfor you using Visual Studio 2017 (assuming you have it installed). You can also specify what version of visual studio you want to use to build the packages.

Installing a Package

  • Open a PowerShell window and navigate to the directory that contains vcpkg.
  • Find the package you want to install using ./vcpkg search <package name>.
  • If your package is listed, install it with ./vcpkg install <package name>.

And that’s pretty much it. But there are a few things to be aware of. One in particular is that the default build type is x86 (32 bit). To change this you can set an environment variable or use what Microsoft calls triplets.

To use the triplets, when intalling a package you just need to append another argument to your command:

./vcpkg install <package name>:x64-windows

or

./vcpkg install <package name> --triplet x64-windows.

To see the available triplets, go to the base vcpkg directory and open the folder appropriately named triplets. In there you’ll find a bunch of .cmake files that specify different build types. If you open one up, you can see the names of the variables that vcpkguses. One of interest is VCPKG_TARGET_ARCHITECTURE. If you wnat to change your default build architecture, this is the variable name you want to use in your environment variables.

Custom Triplet

If you open up the x64-windows.cmake triplet, you should see the following:

set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)

So by default, CRT linkage is dynamic (i.e. via *.dll files) and so is the library linkage. To build static libs you would use the x64-windows-static triplet which will change the linkage to static. The cool thing about vcpkg is that you can create your own, custom triplets. So let’s say you wanted to use Visual Studio 2013 instead of 2017. You could make a new cmake file called x64-vs2013-dynamic.cmake and put the following into it:

set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_PLATFORM_TOOLSET v120)

If you have Visual Studio 2013 properly installed on your machine, you can now install packages with vcpkg using Visual Studio 2013. To do so you just install packages as before, but use your custom triplet instead: ./vcpkg install <package name>:x64-vs2013-dynamic.

Using Packages Installed with vcpkg

One thing I struggled with is how to use vcpkg installs in my own projects. vcpkg thankfully integrates seamlessly with CMake. To use vcpkg all you have to do is pass in the CMAKE_TOOLCHAIN_FILEvariable and point it to the cmake file that is found at <vcpkg directory>/scripts/buildsystems/vcpkg.cmake. All together you’d have something like: cmake "-DCMAKE_TOOLCHAIN_FILE=<path to toolchain file>".

If you use the CMake gui, then you can still specify the toolchain file; you just have to do it when you first configure the project. To do so, open the CMake gui and select your source and build directories. As an example, I’m going to configure the delaunayppproject I’ve been working on. Then click Configure. When you do, you should get a window like the one below:

Click yes and then you’ll be prompted with the following window:

In the radio button options under the generator selector, be sure to select Specify toolchain file for cross-compiling and then hit Next.

You’ll be presented with another window where you can specify the full path to the toolchain file (i.e. the same vcpkg.cmake file specified above).

And that’s it! Now you can use find_package() in cmake like you normally would, but now the installed package locations from vcpkg will also be searched and packages that you have installed should be found automatically.

Conclusion

I hope this short article helped you get started quickly with using vcpkg and hopefully you learned something! I definitely recommend using vcpkg since it has the potential to standardize your package management for larger projects that have a lot of dependencies. Feel free to check out my other blog posts and follow so you don’t miss one!

How to Use vcpkg On Windows的更多相关文章

  1. win10 + vs2017 + vcpkg —— VC++ 打包工具

    vcpkg 是微软 C++ 团队开发的在 Windows 上运行的 C/C++ 项目包管理工具,可以帮助您在 Windows 平台上获取 C 和 C++ 库. vcpkg 自身也是使用 C++ 开发的 ...

  2. Tips for vcpkg

    概述 vcpkg是微软开发的在Windows, Linux和MacOS平台管理C/C++库的开源工具. 快速开始 要求 使用vcpkg需满足如下条件: Windows 10, 8.1, 7, Linu ...

  3. C++ REST SDK i

    Welcome! The C++ REST SDK is a Microsoft project for cloud-based client-server communication in nati ...

  4. [Part 3] 在Ubuntu 16.04源码编译PCL 1.8.1支持VTK和QT

    本文首发于个人博客https://kezunlin.me/post/137aa5fc/,欢迎阅读! Part-3: Install and Configure PCL 1.8.1 with vtk q ...

  5. vcpkg custom triplet

    需求是要弄一个用 pip 发布的python 包,使用 boost-python 桥接 原C++代码,发布时不想带 boost-python 的运行时库,因此需要弄静态的 boost-python库, ...

  6. vcpkg —— VC++ 打包工具

    引用: http://www.tuicool.com/articles/aeiYz2v vcpkg 是微软 C++ 团队开发的在 Windows 上运行的 C/C++ 项目包管理工具,可以帮助您在 W ...

  7. Visual Studio工具 vcpkg简介

    博客参考: https://blog.csdn.net/cjmqas/article/details/79282847#43-%E7%A7%BB%E9%99%A4%E5%85%A8%E5%B1%80% ...

  8. c++ 使用 vcpkg

    1. 打开下载地址:https://github.com/Microsoft/vcpkg 2. 直接下载到本地某个盘 3. 配置环境变量: 4. 打开下载到本地的vcpkg有可能叫vcpkg-mast ...

  9. 我的windows开发环境设定与日常使用指南

    目录 开发相关的软件包安装.设定 Visual Studio 默认设定 鼠标右键添加"在此处打开cmd"选项 git gvim notepad++ VSCode-Insider C ...

随机推荐

  1. C#如何提取.txt文件中的每个字符串

    C#如何提取.txt文件中的每个字符串,并将其存放到一个类中. 将其中的编号 菜名 价格 分别存入不同的数组中. 注:在用ReadLine读取一行信息时为什么读取的中文字符变成了乱码. 20 满意答案 ...

  2. Linux 内核链表实现和使用(一阴一阳,太极生两仪~)

    0. 概述 学习使用一下 linux 内核链表,在实际开发中我们可以高效的使用该链表帮我们做点事, 链表是Linux 内核中常用的最普通的内建数据结构,链表是一种存放和操作可变数据元 素(常称为节点) ...

  3. C# 泛型详解---进阶编程(七)

    今天我们来学习在C#的泛型技巧,传统的课本都在讲解什么是泛型,然后列举一大堆代码示例告诉你什么是泛型,今天我们就来聊聊更加本质的东西,我为什么要用泛型?它是来解决什么问题的?底层原理是什么? 简单来说 ...

  4. 为iOS设计:图形和性能

    在之前的文章里,我们探讨了基于多种不同技术来实现自定义的UIButton,当然不同的技术所涉及到的代码复杂度和难度也不一样.但是我也有意提到了基于不同方法的实现所体现出的性能表现也不一一相同. [在屏 ...

  5. Vue实现刷新当前路由

    Vue点击当前路由实现刷新 Vue点击当前路由实现刷新思路Code实现效果 前言:在后台管理系统中,有这样一个需求点击当前菜单栏时,页面依旧可以刷新. 点击当前路由实现数据请求页面刷新 思路 点击当前 ...

  6. 谨慎使用 FileInfo.Exists 实例方法,而是使用 File.Exists 静态方法替代

    如果你在代码中使用了 FileInfo.Exists 实例方法来判断一个文件是否存在,也许会发现此方法可能错误地判断来一个文件是否真的存在.这是一个坑. 本文将介绍坑的原因,并提供填坑的办法. 本文内 ...

  7. Crazy Computer

    ZS the Coder is coding on a crazy computer. If you don't type in a word for a cconsecutive seconds, ...

  8. UVA1252 【Twenty Questions】

    分析 为了叙述方便,设"心里想的物体"为W.首先在读入时把每个物体转化为一个二进制整数.不难发现,同一个特征不需要问两遍,所以可以用一个集合s表示已经询问的特征集. 在这个集合s中 ...

  9. day13 python学习 迭代器,生成器

    1.可迭代:当我们打印 print(dir([1,2]))   在出现的结果中可以看到包含 '__iter__', 这个方法,#次协议叫做可迭代协议 包含'__iter__'方法的函数就是可迭代函数 ...

  10. stenciljs 学习十 服务器端渲染

      stenciljs提供了 ssr 支持,对于express 最简单的就是使用提供的中间件 express 集成 const express = require('express'); const ...