cmake cannot find libraries installed with vcpkg

boost is currently not installed, but I was expecting that during the execution of the cmake command, vcpkg will download and build needed build packages.

This is not the case as far as I know. You need to install the packages you want with vcpkg beforehand for the triplet you plan to use (i.e. x64-windows). You will then need to ensure that the correct triplet is being used when you run CMake (check the VCPKG_TARGET_TRIPLET variable in your CMakeCache.txt). If it's incorrect, you can change it and re-configure using CMake.

Additionally, based on the error output you're getting, it doesn't seem that xerces has been installed properly either using vcpkg. You can check what is installed with vcpkg by running:

vcpkg list --triplet x64-windows


  1. You need to install the packages beforehand (using vcpkg install ).

(Then you could specify the toolchain as a CMake option:

-DCMAKE_TOOLCHAIN_FILE=C:\path\to\vcpkg\scripts\buildsystems\vcpkg.cmake

but this won't work if you already specify a toolchain, such as when cross-compiling.)

  1. "include" it, instead, to avoid this problem:

Add this line to the project CMakeLists.txt before find_package():

include(/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake)

In theory it's as simple as (assuming vcpkg as installed in C:/vcpkg as it is for github actions);

  1. Install your "foo" package with vcpkg install foo
  2. Make sure your CMakeLists.txt finds and uses the package with;
find_package(FOO)
# Use these instead of the package doesn't have proper cmake package support.
# find_path(FOO_INCLUDE_DIRS foo.h)
# find_library(FOO_LIBRARYS foo)
include_directories(${FOO_INCLUDE_DIRS})
target_link_libraries(myprogram ${FOO_LIBRARIES})                                     
  1. Run cmake with -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake

But... this didn't work for me until I added --triplet x64-windows to the vcpkg install command.

The DCMAKE_TOOLCHAIN_FILE sets the various CMAKE_(SYSTEM_)?(PREFIX|LIBRARY|INCLUDE|FRAMEWORK)_PATH variables to enable the find_*() cmake functions to work, but note that these paths include the VCPKG_TARGET_TRIPLET. In my case the package install with vcpkg install <foo> defaulted to x86-windows but then invoking cmake with -DCMAKE_TOOLCHAIN_FILE=C:/.... defaulted to x64-windows so it couldn't find the the package.

Currently vcpkg defaults to the older x86 target, but modern Visual Studio (as used by githup actions) defaults to x64. The fix was to install the package with vcpkg -triplet x64-windows install <foo>. It took me way too long going down too many red-herring rabbit holes to discover this.