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. centos 7安装tomcat

    1.下载安装包 http://tomcat.apache.org/download-80.cgi 2.安装tomcat 注:安装前需要安装jdk环境 #解压 [root@localhost soft] ...

  2. webpack 添加 jquery 插件

    webpack.base.config.js 加入以下配置: , plugins: [ new webpack.ProvidePlugin({ jQuery: 'jquery', $: 'jquery ...

  3. 基础练习 FJ的字符串

    基础练习 FJ的字符串   时间限制:1.0s   内存限制:512.0MB        问题描述 FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = “ABA” A3 = “ABACAB ...

  4. 第十七篇 make的路径搜索综合实践

     本节我们编写路径搜索相关的makefile,具体需求如下:  1.工程项目中不希望源码文件夹在编译时被改动(只读文件夹).  2.在编译时自动创建文件夹(build)用于存放编译结果.  3.编译过 ...

  5. file.replace

    一.简介 salt file.replace 文件内容处理函数,类似于ansible的lineinfile模块 二.参数介绍 name 被编辑文件的绝对路径,支持软链接 pattern 常规表达式,使 ...

  6. Error: timed out while waiting for target halted

    /************************************************************************************ * Error: timed ...

  7. [LeetCode&Python] Problem 589. N-ary Tree Preorder Traversal

    Given an n-ary tree, return the preorder traversal of its nodes' values. For example, given a 3-ary  ...

  8. Java-JDK & Android SDK下载安装及配置教程

    转自:http://blog.csdn.net/dr_neo/article/details/49870587 第一步.安装JDK: 第二步.安装Eclipse: 第三步.下载并安装AndroidSD ...

  9. 【spring源码分析】面向切面编程架构设计

    2 注解说明 2.1 @Aspect 作用是把当前类标识为一个切面供容器读取 2.2 @Before标识一个前置增强方法,相当于BeforeAdvice的功能,相似功能的还有 2.3 @AfterRe ...

  10. PipelineDB 1.0.0 docker 运行

    PipelineDB 1.0 是基于标准的pg 扩展来做的,安装也更方便了,目前还没有对应的docker 镜像 所以参考timescaledb 做了一个,方便测试以及使用 参考地址 https://g ...