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. JSP--TOMCAT-MYSQL web页面删除

    deleteStudentjsp.jsp页面代码 <%@ page language="java" contentType="text/html; charset= ...

  2. 公告:《那些年,追寻Jmeter的足迹》上线

    在我们团队的努力下,我们<那些年,追寻Jmeter的足迹>手册第1版本工作完成(后面还会有第2版本),比较偏基础,这是汇集我们团队的经验和团队需要用到的知识点来整理的,在第2个版本,我们整 ...

  3. 计算 S=a+aa+aaa+aaaa+a.......a【转载】

    package java算法; import java.util.Scanner; /* * 计算 S=a+aa+aaa+aaaa+a.......a */ public class numadd { ...

  4. IOS 获取中英文字符串长度

    //得到中英文混合字符串长度 方法1 - (int)convertToInt:(NSString*)strtemp { int strlength = 0; char* p = (char*)[str ...

  5. OK335xS pwm device register hacking

    /************************************************************************* * OK335xS pwm device regi ...

  6. WC游记

    第一次来WC,感觉这种集训真吼啊 day0 火车上快速补习了莫队,和AC自动姬,AC自动姬以前就会写只不过太久没写忘了我会了= = 莫队只是学习了做法,还没有做过题…… 本来想再复习一下后缀数组,然后 ...

  7. vulcanjs 核心架构概念

    基于包的架构 为了保证系统的灵活以及可扩展,vulcanjs 使用基于包的架构设计,每一个功能都是一个包,可以方便的添加,移除 扩展.而不是修改 vulcan 的设计哲学是进行系统扩展,而不是编辑修改 ...

  8. oracle 获取星期日期

    oracle 中的计算如下: 计算本星期的起始结束日期--得到星期一的日期select trunc(sysdate,''DD'')-to_char(sysdate,''D'')+2 from dual ...

  9. TensorFlow笔记-03-张量,计算图,会话

    TensorFlow笔记-03-张量,计算图,会话 搭建你的第一个神经网络,总结搭建八股 基于TensorFlow的NN:用张量表示数据,用计算图搭建神经网络,用会话执行计算图,优化线上的权重(参数) ...

  10. MongoDB注册Windows服务启动

    下载MongoDB安装到:E:\Work_App\MongoDB 这个目录 安装:E:\Work_App\MongoDB (安装在专门的目录中) 配置: 1.在E:\Work_App\MongoDB\ ...