How to use vcpkg with Visual Studio Code on Linux
Install vcpkg
https://docs.microsoft.com/en-us/cpp/build/vcpkg?view=msvc-160#installation
After this, you should get a path such as /home/yingshaoxo/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake
Install CMake Tools
extension for VSCode
https://code.visualstudio.com/docs/cpp/cmake-linux
Don’t forget to use Ctrl+Shift+P
to create a fresh new Cmake: Quick Start
configure file.
Change the settings of CMake Tools
For Build Args
and Configure Args
, you add:
-DCMAKE_TOOLCHAIN_FILE=/home/yingshaoxo/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake
Modify CMakeLists.txt
after the modifying, it should look like this:
cmake_minimum_required(VERSION 3.0.0)
project(gtkmm_test VERSION 0.1.0)
set(CMAKE_TOOLCHAIN_FILE /home/yingshaoxo/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake)
include(CTest)
enable_testing()
add_executable(gtkmm_test main.cpp)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
Configure and Debug
Remember, now, F5
is no longer work for you.
You have to use Ctrl+Shift+P
to select Cmake: debug
to run your code.