Tips for vcpkg
概述
vcpkg是微软开发的在Windows, Linux和MacOS平台管理C/C++库的开源工具。
快速开始
要求
使用vcpkg需满足如下条件:
- Windows 10, 8.1, 7, Linux, or MacOS
- Visual Studio 2017 or Visual Studio 2015 Update 3 (on Windows)
- Git
- CMake 3.10.2 (optional)
安装vcpkg
> git clone https://github.com/Microsoft/vcpkg
> cd vcpkg
PS> .\bootstrap-vcpkg.bat
Ubuntu:~/$ ./bootstrap-vcpkg.sh
为了让计算机的所有用户都可以使用vcpkg,运行如下命令(首次运行需管理员权限):
PS> .\vcpkg integrate install
Ubuntu:~/$ ./vcpkg integrate install
安装库
通过如下命令便可以安装库:
PS> .\vcpkg install sdl2 curl
Ubuntu:~/$ ./vcpkg install sdl2 curl
对于Windows
平台,vcpkg
默认安装32位库,如果想要设置为默认安装64位库,在环境变量中加上VCPKG_DEFAULT_TRIPLET=x64-windows
即可。
如果你在安装库时下载速度非常慢甚至下载失败,可以拷贝下载链接自行下载好库的压缩包,然后放在downloads
文件夹,这样vcpkg
便直接使用下载好的库来编译安装。
对于有些库,默认可能不是所有的依赖都安装,如ceres-solver,默认不支持suitesparse,cxsparse
,此时可以通过命令.\vcpkg install ceres[suitesparse,cxsparse]:x64-windows --recurse
重新安装,其中--recurse
表示可以卸载之前的库。更多install参数可以通过命令.\vcpkg help install
查看。
再比如支持cuda的opencv版本,可以通过命令.\vcpkg install opencv[cuda]:x64-windows
来安装。
卸载vcpkg
直接删除vcpkg的文件夹即可。
使用库
CMake
在CMake中使用通过vcpkg安装的库的最佳方式是通过工具链文件(toolchain file) scripts/buildsystems/vcpkg.cmake
,让安装的库通过find_package()
被发现。
要使用这个文件,只需通过命令-DCMAKE_TOOLCHAIN_FILE=[vcpkg root]/scripts/buildsystems/vcpkg.cmake
将其加入CMake命令行中即可。例如
cmake .. -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake (Linux/MacOS)
cmake .. -DCMAKE_TOOLCHAIN_FILE=vcpkg\scripts\buildsystems\vcpkg.cmake (Windows)
再比如,如果要用VS2017编译器,输入下面命令即可:
cmake .. -DCMAKE_TOOLCHAIN_FILE=D:\vcpkg\scripts\buildsystems\vcpkg.cmake -G "Visual Studio 15 2017 Win64"
还有一种方法,直接在CMakeLists.txt
文件中指定CMAKE_TOOLCHAIN_FILE
,即
set(CMAKE_TOOLCHAIN_FILE "D:\vcpkg\scripts\buildsystems\vcpkg.cmake")
project(PROJECT_NAME)
这里需要注意的是,设置CMAKE_TOOLCHAIN_FILE
要在project()
命令之前。另外多说一句,类似CMAKE_TOOLCHAIN_FILE
, CMAKE_SYSTEM_NAME
, CMAKE_C_COMPILER
等这些变量都要在project()
命令之前设定,不然CMake
仍然会按照默认的设置来。
VisualStudio
在VS中,所有已经安装的库都被VS项目自动包含(通过前面提到的vcpkg integrate install
命令实现),无需配置便可直接使用。
CLion
在CLion中的配置如下File -> Settings -> Build, Execution, Deployment -> CMake,在CMake Options中添加-DCMAKE_TOOLCHAIN_FILE=[vcpkg root]/scripts/buildsystems/vcpkg.cmake
vcpkg命令
vcpkg help
: 帮助vcpkg search
: 搜索库vcpkg install
: 安装库
对于Windows
平台.\vcpkg install openmesh:x86-windows
:安装32位库.\vcpkg install openmesh:x64-windows
:安装64位库.\vcpkg install openmesh:x64-windows-static
安装64位静态库
vcpkg list
:列出所有已经安装的库vcpkg upgrade
:列出所有可以升级的库,如果需要升级,需额外添加--no-dry-run
命令vcpkg update
vcpkg remove
:移除某个已经安装的库,如果需要移除依赖该库的其他库,添加--recurse
命令
vcpkg文件夹构成
- buildtrees -- contains subfolders of sources from which each library is built
- docs -- documentation and examples
- downloads -- cached copies of any downloaded tools or sources. vcpkg searches here first when you run the install command
- installed-- Contains the headers and binaries for each installed library. When you integrate with Visual Studio, you are essentially telling it add this folder to its search paths
- packages -- Internal folder for staging between installs
- ports -- Files that describe each library in the catalog, its version, and where to download it. You can add your own ports if needed
- scripts -- Scripts (cmake, powershell) used by vcpkg
- toolsrc -- C++ source code for vcpkg and related components
- triplets -- Contains the settings for each supported target platform (for example, x86-windows or x64-uwp)
更新vcpkg
在vcpkg根目录下的ports文件夹中可以看到当前版本包含的所有库,但由于vcpkg项目正在活跃开发中,有时候有些库在你当前的版本中并没有加入,这时可以考虑更新vcpkg。首先拉取vcpkg的远程仓库,更新本地仓库:
git fetch origin master:temp // 从远程的origin仓库的master分支下载到本地并新建一个分支temp
git diff temp // 比较本地的仓库和远程仓库的区别
git merge temp // 合并temp分支到master分支
git branch -d temp // 如果不想要temp分支了,可以删除此分支
然后重新编译生成vcpkg.exe工具
PS> .\bootstrap-vcpkg.bat
Linux:~/$ ./bootstrap-vcpkg.sh
然后可以通过命令.\vcpkg update
.\vcpkg upgrade
更新已经安装好的库。再通过install
命令安装新的库。
参考
- vcpkg-github
- vcpkg-docs
- Vcpkg: a tool to acquire and build C++ open source libraries on Windows
- CMAKE_TOOLCHAIN_FILE only recognized on command line
Tips for vcpkg的更多相关文章
- clion结合vcpkg以及GTest的使用
目录 一.vcpkg简介.下载和使用 1. vcpkg是什么 2. vcpkg下载 3. 使用vcpkg下载第三方库 二.clion结合vcpkg 1. 方法一:使用环境变量 2. 方法二:添加cma ...
- Mac上MySQL忘记root密码且没有权限的处理办法&workbench的一些tips (转)
忘记Root密码肿么办 Mac上安装MySQL就不多说了,去mysql的官网上下载最新的mysql包以及workbench,先安装哪个影响都不大.如果你是第一次安装,在mysql安装完成之后,会弹出来 ...
- 【Tips】史上最全H1B问题合辑——保持H1B身份终级篇
[Tips]史上最全H1B问题合辑——保持H1B身份终级篇 2015-04-10留学小助手留学小助手 留学小助手 微信号 liuxue_xiaozhushou 功能介绍 提供最真实全面的留学干货,帮您 ...
- layer.js中layer.tips
<script src="~/Content/js/layer/layer.js"></script> layer.tips('名称不能为空', '#pro ...
- HTML 最简单的tips 怎么支持指定DIV显示提示信息
<body> <style type="text/css"> a.link{position:relative;} a.link div.tips{ bor ...
- CSS:CSS使用Tips
Css是前端开发中效果展现的主要部分之一,良好的Css书写习惯可以为实际的项目开发提高效率,也可以为实现良好的团队合作提供保证. 一般新手在使用Css的时候经常会犯一些错误,出现一些不经意的漏洞,如果 ...
- 【读书笔记】100个Switf必备tips
声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblogs.com 正文 1.Selector 在Swi ...
- 【转】40个良好用户界面Tips
一个良好的用户界面应具有高转换率,并且易于使用.但要用户体验良好并不容易做到,下面我们整理了40个良好用户界面Tips,希望能对你有帮助! 1 尽量使用单列而不是多列布局 单列布局能够让对全局有更好的 ...
- 转:Eclipse Search Tips
from: https://github.com/ajermakovics/eclipse-instasearch/wiki/Eclipse-search-tips Eclipse Search T ...
随机推荐
- 微服务学习及.net core入门教程
https://www.cnblogs.com/jackyfei/p/12067708.html https://www.cnblogs.com/jesse2013/ http://video.jes ...
- docker-compose.yml的使用
docker-compose.yml包含version.services.networks3大部分 services的书写规则 1.iamge services: web: # 服务名称,用户自定义 ...
- javascript权威指南第21章 Ajax和Comet
function createXHR(){ if(typeof XMLHttpRequest !='undefined'){ return new XMLHttpRequest(); }else if ...
- MongoDB 4.0 事务实现解析
MongoDB 4.0 引入的事务功能,支持多文档ACID特性,例如使用 mongo shell 进行事务操作 > s = db.getMongo().startSession() sessio ...
- PostgreSQL 使用PG_Rman进行物理备份
背景 在Oracle下我们可以使用rman进行物理备份,支持数据库的全量.增量.归档的备份模式而PostgreSQL作为开源数据库,近些时间来也一直向商业版数据库看齐,也推出了开源功工具pg_rman ...
- luogu 2934
同 bzoj3694 需要先求出最短路树 #include <iostream> #include <cstdio> #include <algorithm> #i ...
- Cogs 13. 运输问题4(费用流)
运输问题4 ★★☆ 输入文件:maxflowd.in 输出文件:maxflowd.out 简单对比 时间限制:1 s 内存限制:128 MB [问题描述] 一个工厂每天生产若干商品,需运输到销售部门进 ...
- maven 安装 jar 包
注意 jar 包路径,和版本号 mvn install:install-file -Dfile=E:\ChromeBox\box\kaptcha-2.3.2\kaptcha-2.3.2.jar -Dg ...
- 配置Jupyter Notebook
配置Jupyter Notebook 1 修改Jupyter Notebook的工作目录 Jupyter默认打开的是用户目录,使用如下步骤自行修改: CMD生成Jupyter配置文件: (python ...
- python生成二维码(简易)
首先要的配置: pillow image qrcode zxing 然后直接上代码: import PIL import qrcode # 实例化二维码生成类 qr = qrcode.QRCode( ...