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 .bat
file 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 vcpkg
uses. 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_FILE
variable 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 delaunaypp
project 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 ...
随机推荐
- grafana设置Alert阈值和邮件报警
首先我们需要在机器上开启smtp/25服务,这里有一个坑,注意,云主机为了防止滥发邮件已经封掉了smtp的所有通信,所以云主机发邮件是有问题的. 安装sendmail,ubuntu用apt,cento ...
- ES6 Generator 学习笔记一
Generator 函数是 ES6 提供的一种异步编程解决方案,语法行为与传统函数完全不同. Generator 函数有多种理解角度.从语法上,首先可以把它理解成,Generator 函数是一个状态机 ...
- 查看camera设备-linux
前言 本文介绍如何在linux平台查看是否有camera外设. 操作过程 1.打开shell,输入以下命令: ls /dev/video* 即可查看是否有camera外设: 2.如果确实连接了came ...
- c4 L3-001 找零钱 (简单01背包-输出最小字典序解(用vector保存当前最优解))
#include <iostream> #include <algorithm> #include <vector> #include <cstdio> ...
- 微信小程序开发过程中出现问题及解答
1.wx.uploadFile上传图片,控制台抛出错误"uploadFile:fail Error:Hostname/IP doesn't match certificate's altna ...
- hdu 5182 结构体排序
BC # 32 : 打 BC 的时候没看全三个关键字,WA 了五发,花了近一小时,问了一下才发现少看一个条件,于是顺利给跪. 题意:给出若干城市的两次空气质量,首先按空气质量差排序,若相等则按第二次排 ...
- proc文件系统漫谈
1. /proc/buddyinfo:/proc/buddyinfo是linuxbuddy系统管理物理内存的debug信息. 在linux中使用buddy算法解决物理内存的外碎片问题,其把所有空闲的内 ...
- cocos2dx学习资料
[9秒原创]cocos2d-x——CCScrollView用法 http://www.9miao.com/thread-45619-1-1.html [9秒原创]cocos2d-x——场景切换效果示例 ...
- junit 知识点
JUnit 测试框架具有以下重要特性: 测试工具 测试套件 测试运行器 测试分类 测试工具 测试工具是一整套固定的工具用于基线测试.测试工具的目的是为了确保测试能够在共享且固定的环境中运行,因此保证测 ...
- PHP安全相关的配置(2)
php用越来越多!安全问题更为重要!这里讲解如果安全配置php.ini 安全配置一 (1) 打开php的安全模式 php的安全模式是个非常重要的内嵌的安全机制,能够控制一些php中的函数,比如syst ...