0.内容概览
1.vcpkg工具安装
>> git clone https://github.com/microsoft/vcpkg
>> .\vcpkg\bootstrap-vcpkg.bat
2.vcpkg包管理
- (1) 基础语法
# 1.包安装
>> vcpkg install [package name]:[platform name]
# 2.包卸载
>> vcpkg remove [package name]
# 3.列出已安装包
>> vcpkg list
# 4.搜索可安装包
>> vcpkg search [package name]
# 5.查看vcpkg版本
>> vcpkg version
# 6.将安装包生成集成
>> vcpkg integrate install
# 7.生成项目引入Nuget包配置文件
>> vcpkg integrate project
# 8.删除安装包集成
>> vcpkg integrate remove
- (2) 举例说明
# 1.opencv
>> cd .\vcpkg\
# 2.安装opencv3
>> vcpkg install opencv3:x64-windows
# 3.安装opencv4
>> vcpkg install opencv:x64-windows
# 4.安装glad
>> vcpkg install glad:x64-windows
# 5.安装glfw3
>> vcpkg install glfw3:x64-windows
- (3) CMake集成
# 1.opencv
set (OBJECTS_TO_LINK "")
find_package(OpenCV REQUIRED)
if (${OPENCV_FOUND})
message(STATUS "Found OpenCV: ${OpenCV_VERSION}")
include_directories(${OpenCV_INCLUDE_DIRS})
list(APPEND OBJECTS_TO_LINK ${OpenCV_LIBS})
endif (${OPENCV_FOUND})
# 2.glfw3
find_package(glfw3 CONFIG REQUIRED)
list(APPEND OBJECTS_TO_LINK glfw)
# 3.glad
find_package(glad CONFIG REQUIRED)
list(APPEND OBJECTS_TO_LINK glad::glad)
3.vcpkg集成
3.1生成集成配置文件
# 1.集成到全局
>> vcpkg integrate install
# 2.生成配置文件
>> vcpkg integrate project
3.2 visual studio配置
- (1) 以前路径是[vcpkg路径]/scripts/buildsystems
- (2) 最新版路径是[vcpkg路径]
“工具” -> “NuGet包管理器” -> “程序包管理器配置” ->“程序包源” -> 单击"加号" -> “名称”设置为“vcpkg”,“源(s)”设置为“[vcpkg路径]” ->“确定”
3.3 配置到项目
“工具” -> “NuGet包管理器” -> “管理解决方案的NuGet程序包(N)”-> “程序包源”切换为“vcpkg” -> “浏览” -> 选择vcpkg包 -> 勾选当前项目 -> 点击“安装”
4.vcpkg测试
#include <opencv2/opencv.hpp>
int main(int argc, char *argv[]) {
cv::Mat image = cv::imread("test.jpg");
cv::imshow("result", image);
cv::waitKey(0);
return 0;
}
注意:由于OpenCV可以同时安装OpenCV3和OpenCV4两个版本,因此头文件目录包含时,需要手动添加一下OpenCV3的头文件包含路径([vcpkg路径]\installed\x64-windows\include\opencv3),添加方法:
“项目”->“属性”->“VC++目录”->“包含目录”->“编辑”->添加路径"[vcpkg路径]\installed\x64-windows\include\opencv3"->“确定”
5.vcpkg在CMake中使用
>> mkdir build && cd build
>> cmake .. -DCMAKE_TOOLCHAIN_FILE=[vcpkg路径]/scripts/buildsystems/vcpkg.cmake
6.参考资料
- [1] vcpkg