Microsoft vcpkg
Published:
(work in progress…)
Unlike Linux, the Microsoft Operating System (OS) does not have a central library controller. The vcpkg can partially do the job, but sometimes with a bit extra tuning. Besides, there are several package manager exists. One popular alternative option is the Conan. However, here are some instructions on vcpkg, could be helpful for the beginners.
MS-vcpkg
vcpkg has two operation modes: classic and manifest. During the classic mode, installs packages globally in a shared installed directory (e.g., C:\vcpkg\installed\x64-windows), managed by explicit vcpkg install commands, like traditional system package managers (apt, brew) but local to the vcpkg root, while manifest mode uses a project-specific vcpkg.json file for declarative dependency management, installing packages into a project-local vcpkg_installed folder, offering better version control and project isolation. Moreover, the manifest mode is often recommended for most of the new projects due to its explicit dependency declaration and easier reproducibility, whereas classic mode suits simpler, shared library setup.
Clone and Setting
- Clone the repository in any suitable directory (often prefer
C:/drive). Therefore, for githubcd C:\ git clone --recursive https://github.com/microsoft/vcpkg.git - Then
Environment Variables >> System Variables >> path >> new >> (add) C:\vcpkgHowever, I found no visible effect whether set it or not.
Install vcpkg
- run
.\bootstrap-vcpkg.bat- Windows Power Shell
.\vcpkg integrate install(!important: this will integrate with current visual studio)- Save a copy of the CMake Instruction for future use for me:
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
Search, Install, and Integration
- Search
.\vcpkg.exe search library_name(e.g., opencv) - Install
.\vcpkg.exe install library_name:x64-windows(:x64-windows for x64 machine, otherwise x86 is default). This might take a while!. - Someone can find the downloaded library under installed folder, e.g.,
C:\vcpkg\installed, also underpackagesfolder. Also,
.\vcpkg.exe listwill return all installed libraries- After installing the library, run
.\vcpkg.exe integrate installto integrate with visual studio.- This
integrateis important if someone want to access files easily underC:\vcpkg\installed\x64-windows\includedirectory
- This
Uninstalling packages
- to uninstall particular package
.\vcpkg.exe remove package_name:x64-windows - sometimes it may need to use
--recursecommand if other packages are depend on that packages, e.g.,.\vcpkg.exe --recurse remove python3:x64-windows - to uninstall all packages
.\vcpkg.exe remove *:x64-windows - Against
.\vcpkg.exe integrate->vcpkgis deleted. To removevcpkg integrate removeneed to call.
Some packages like boost, and qt5 are “meta-packages”. This means that these packages themselves are empty, and what they do is depend on other packages to install them all together as a convenience (not clear).
Using in C++ (tried on Visual Studio 2022) project
- Create an empty project
- Check what
debugmachine it isx86/x64 - Simply use
#include<start_the_library_name>, the library will appear - If not, then have to do it a bit manually (if there is any other solution, I will add later)
- type
.\vcpkg.exe integrate projectin the power shell and follow the instruction. Generally the instruction is: - With a project open, go to
Tools->NuGet Package Manager->Package Manager Consoleand paste:Install-Package vcpkg.C.vcpkg -Source "C:\vcpkg\scripts\buildsystems"
- type
vcpkg to Cmake
- How to add to CMake command line
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake?
cmake_minimum_required (VERSION x.x)
set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
project (project_name)
file (GLOB_REUSE fileCollection "Source/*.h"
"Source/*.cpp"
)
find_package(assimp CONFIG REQUIRED)
add_executable (project_name ${fileCollection})
#find_package can also be here
target_link_libraries(project_name PRIVATE assimp::assimp)
