Microsoft VCPKG

2 minute read

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: classic and manifest mode

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
  • 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 under packages folder.
  • Also, .\vcpkg.exe list will return all installed libraries

  • After installing the library, run .\vcpkg.exe integrate install to integrate with visual studio.
    • This integrate is important if you want to access files easily under C:\vcpkg\installed\x64-windows\include directory

1.4. Uninstalling packages

  • to uninstall particular package .\vcpkg.exe remove package_name:x64-windows
  • sometimes it may need to use --recurse command 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 -> vcpkg is deleted. To remove vcpkg integrate remove need 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 debug machine it is x86/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 project in the power shell and follow the instruction. Generally the instruction is:
    • With a project open, go to Tools->NuGet Package Manager->Package Manager Console and paste:
    • ` Install-Package vcpkg.C.vcpkg -Source “C:\vcpkg\scripts\buildsystems”`

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)

Resources