How to Use vcpkg On Windows
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的更多相关文章
- win10 + vs2017 + vcpkg —— VC++ 打包工具
vcpkg 是微软 C++ 团队开发的在 Windows 上运行的 C/C++ 项目包管理工具,可以帮助您在 Windows 平台上获取 C 和 C++ 库. vcpkg 自身也是使用 C++ 开发的 ...
- Tips for vcpkg
概述 vcpkg是微软开发的在Windows, Linux和MacOS平台管理C/C++库的开源工具. 快速开始 要求 使用vcpkg需满足如下条件: Windows 10, 8.1, 7, Linu ...
- C++ REST SDK i
Welcome! The C++ REST SDK is a Microsoft project for cloud-based client-server communication in nati ...
- [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 ...
- vcpkg custom triplet
需求是要弄一个用 pip 发布的python 包,使用 boost-python 桥接 原C++代码,发布时不想带 boost-python 的运行时库,因此需要弄静态的 boost-python库, ...
- vcpkg —— VC++ 打包工具
引用: http://www.tuicool.com/articles/aeiYz2v vcpkg 是微软 C++ 团队开发的在 Windows 上运行的 C/C++ 项目包管理工具,可以帮助您在 W ...
- Visual Studio工具 vcpkg简介
博客参考: https://blog.csdn.net/cjmqas/article/details/79282847#43-%E7%A7%BB%E9%99%A4%E5%85%A8%E5%B1%80% ...
- c++ 使用 vcpkg
1. 打开下载地址:https://github.com/Microsoft/vcpkg 2. 直接下载到本地某个盘 3. 配置环境变量: 4. 打开下载到本地的vcpkg有可能叫vcpkg-mast ...
- 我的windows开发环境设定与日常使用指南
目录 开发相关的软件包安装.设定 Visual Studio 默认设定 鼠标右键添加"在此处打开cmd"选项 git gvim notepad++ VSCode-Insider C ...
随机推荐
- 1.1.4 A+B for Input-Output Practice (V)
A+B for Input-Output Practice (V) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 【微信小程序推广营销】教你微信小程序SEO优化,让你的小程序快人一步抢占先机
今年一月份上线的小程序,经过近一年的沉淀发酵,现在也进入了快速发展期. 在未来肯定会有越来越多的小程序诞生,小程序多了就需要搜索,那么如何让自己的小程序在众多的小程序中脱颖而出,这就需要小程序SEO优 ...
- 2.3 linux中的信号分析 阻塞、未达
信号的阻塞.未达: linux中进程1向进程2发送信号,要经过内核,内核会维护一个进程对某个信号的状态,如下图所示: 当进程1向进程2发送信号时,信号的传递过程在内核中是有状态的,内核首先要检查这个信 ...
- magento的xml文件解读
其中显示页面的getChildHtml(’')函数是取xml文件中的block中的name属性的:
- 常用增强学习实验环境 I (MuJoCo, OpenAI Gym, rllab, DeepMind Lab, TORCS, PySC2) (转载)
原文地址:http://blog.csdn.net/jinzhuojun/article/details/77144590 和其它的机器学习方向一样,强化学习(Reinforcement Learni ...
- 截图保存 matlab
file=dir('D:\Program Files\MATLAB\R2014a\bin\MyPro\OCR\图像中时间识别\')for i=3:length(file) path= strcat(' ...
- Generate And Play A Tone In Android hacking
/*********************************************************************************** * Generate And ...
- git中的标签
/*游戏或者运动才能让我短暂的忘记心痛,现如今感觉学习比游戏和运动还重要——曾少锋*/ 1.创建标签: 对于标签来说大家都很熟悉,简单说就是将一个很长的门牌号用另外一个名字来取代,并且好记. 其实利 ...
- CodeForces - 1093F:Vasya and Array (DP&计数)
题意:N,K,L,以及给定长度为N的序列,表示其对应的颜色,-1表示还没有涂色,现在让你去涂色,使得最后没有大于等于L的连续的同色的情况. 思路:我们用dp[i][j]表示第i个位置颜色为j的合法方案 ...
- C4D 计算体积和表面积插件
前段时间,由于有个模型要做3D打印,所以需要知道模型的体积以及表面积,以便计算价格. 我用的是C4D,恕我愚昧,在C4D上没找到自带的. 在网上找了好久,才找到一个由法国开发名为aire_volume ...