Microsoft VCPKG
Published:
(work in progress…)
Unlike Linux, the Microsoft Operating System does not have a central library controller. The VCPKG can partially do the job with a bit extra tuning. There are several alternatives of VCPKG, one popular alternative option is the Conan. Here are some instructions on VCPKG that I tried sometimes.
1. MS-VCPKG
- vcpkg has two operation modes:
classicandmanifestmode
1.1. Cloning and Setting
- Clone the repository in any directory (often prefer C: drive)
- github:
cd C:\ - github:
git clone --recursive https://github.com/microsoft/vcpkg.git
- github:
- Set (below):
Environment Variables >>
System Variables >>
path >> new >>
C:\vcpkg
I found no effect whether set it or not
1.2. Installing 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"
1.3. Searching-Installing-Integrating
- 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!. - You 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 you want to access files easily underC:\vcpkg\installed\x64-windows\includedirectory
- This
1.4. 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).
1.5. Using in C++ (visual studio) 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 you 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
1.6. 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)
