Installing vcpkg on Windows

Using vcpkg with CMake Projects

How can I integrate vcpkg with my CMake projects on Windows?

Abstract art representing computer programming

Integrating vcpkg with CMake projects on Windows is straightforward. Here's how you can do it:

Step 1: Make sure you have installed and integrated vcpkg with your build system as described in the lesson.

Step 2: In your CMake project, add the following lines to your CMakeLists.txt file before the project() command:

cmake_minimum_required(VERSION 3.0)

set(CMAKE_TOOLCHAIN_FILE "{vcpkg_root}/scripts/buildsystems/vcpkg.cmake")

Replace {vcpkg_root} with the actual path to your vcpkg installation directory.

Step 3: Use find_package() to locate the libraries you want to use in your project. For example:

find_package(spdlog CONFIG REQUIRED)

Step 4: Link the libraries to your target using target_link_libraries():

target_link_libraries(your_target PRIVATE spdlog::spdlog)

Step 5: Configure and build your project using CMake as usual.

By setting the CMAKE_TOOLCHAIN_FILE variable and using find_package(), CMake will automatically locate the installed vcpkg packages and make them available for linking in your project.

Answers to questions are automatically generated and may not have been reviewed.

A computer programmer
Part of the course:

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Free, unlimited access

This course includes:

  • 124 Lessons
  • 550+ Code Samples
  • 96% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Free, Unlimited Access

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Screenshot from Warhammer: Total War
Screenshot from Tomb Raider
Screenshot from Jedi: Fallen Order
Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved