Vcpkg是什么
VC++ Packaging Tool,用来帮助你在Windows上获取C/C++库,目前尚处理预览状态。
快速上手
- 前提条件:
- Visual Studio 2015 Update 3
- path变量路径下有git.exe
- 克隆仓库
git clone https://github.com/Microsoft/vcpkg.git
- 切换到源代码路径,执行构造
powershell -exec bypass scripts\bootstrap.ps1
- 设定user-wide整合(初次执行需要管理员权限)
vcpkg.exe integrate install
- 安装库
vcpkg.exe install sqlite3 boost
- 最后,在Visual Studio 2015中新建工程,只需要
#include
对应的头文件即可使用。
特点
免配置
无需配置include、library路径,无需配置library依赖,自动识别win32/x64自动复制依赖
如果依赖于某个library,则运行/打包时需要复制dll到对应路径,而Vcpkg会完成这一步骤
示例sqlite
安装
查询sqlite对应的名称
λ vcpkg.exe search sqlite
libodb-sqlite 2.4.0 Sqlite support for the ODB ORM library
sqlite3 3.15.0 SQLite is a software library that implements a se...
If your library is not listed, please open an issue at:
https://github.com/Microsoft/vcpkg/issues
然后安装sqlite3
λ vcpkg.exe install sqlite3
-- CURRENT_INSTALLED_DIR=D:/vcpkg/installed/x86-windows
-- DOWNLOADS=D:/vcpkg/downloads
-- CURRENT_PACKAGES_DIR=D:/vcpkg/packages/sqlite3_x86-windows
-- CURRENT_BUILDTREES_DIR=D:/vcpkg/buildtrees/sqlite3
-- CURRENT_PORT_DIR=D:/vcpkg/ports/sqlite3/.
-- Downloading https://sqlite.org/2016/sqlite-amalgamation-3150000.zip...
-- Downloading https://sqlite.org/2016/sqlite-amalgamation-3150000.zip... OK
-- Testing integrity of downloaded file...
-- Testing integrity of downloaded file... OK
-- Extracting source D:/vcpkg/downloads/sqlite-amalgamation-3150000.zip
-- Extracting done
-- Configuring x86-windows-rel
-- Configuring x86-windows-rel done
-- Configuring x86-windows-dbg
-- Configuring x86-windows-dbg done
-- Build x86-windows-rel
-- Build x86-windows-rel done
-- Build x86-windows-dbg
-- Build x86-windows-dbg done
-- Package x86-windows-rel
-- Package x86-windows-rel done
-- Package x86-windows-dbg
-- Package x86-windows-dbg done
-- Warning: Could not find a matching pdb file for:
D:/vcpkg/packages/sqlite3_x86-windows/bin/sqlite3.dll
D:/vcpkg/packages/sqlite3_x86-windows/debug/bin/sqlite3.dll
-- Performing post-build validation
-- Performing post-build validation done
Package sqlite3:x86-windows is installed
确认是否安装成功
vcpkg.exe list
安装64位版本
vcpkg.exe install sqlite3:x64-windows
使用
打开Visual Studio 2015 新建工程,main.cpp如下
#include <sqlite3.h>
#include <stdio.h>
int main(int argc,char** argv)
{
printf("%s\n",sqlite3_libversion()):
return 0;
}
编译运行
FAQ
是否支持Visual Studio 2010 ?
否,后续我会介绍Vcpkg用到的“知识点”,可以为Visual Studio 2010开发相应工具提供借鉴。是否支持静态编译库
是,例如vcpkg.exe install xxx:x86-windows-static
没有我需要的库怎么办
自己写,后续我会介绍如何向Vcpkg新增库