3

I'm adventuring myself into compiling a CMake project using Visual Studio, targeting WSL 1. Following Microsoft's tutorial to setup a CMake project in Visual Studio and debugging on WSL works fine. Things break when I try to install and use packages using Microsoft's vcpkg package manager after installing vcpkg into a separate Windows directory and integrating it into Visual Studio.

A simple example that fails:

# CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(test)
find_package(protobuf CONFIG REQUIRED)

with the following error message:

CMake Error at C:\test\CMakeLists.txt:5 (find_package): Could not find a package configuration file provided by "protobuf" with any of the following names

protobufConfig.cmake
protobuf-config.cmake

Add the installation prefix of "unofficial-sqlite3" to CMAKE_PREFIX_PATH or set "protobuf_DIR" to a directory containing one of the above files. If "protobuf" provides a separate development package or SDK, be sure it has been installed.

I'm getting Intellisense to recognize find_package and suggesting to install the package or copying the vcpkg command to clipboard.

The CMake toolchain file is pointing to the "C:/vcpkg/scripts/buildsystems/vcpkg.cmake" file in the WSL-GCC-Debug configuration settings. Installing vcpkg on the Linux system and setting the CMake toolchain file to the corresponding path creates the exact same error output.

Running the "vcpkg install protobuf:x64-linux" command in the terminal creates the following output:

Computing installation plan...
The following packages will be built and installed:
    protobuf[core]:x64-linux -> 3.14.0#1
Detecting compiler hash for triplet x64-linux...
Error: while detecting compiler information:
The log content at C:\vcpkg\buildtrees\detect_compiler\stdout-x64-linux.log is:
-- Configuring x64-linux
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:108 (message):
    Command failed: ninja -v
    Working Directory: C:/vcpkg/buildtrees/detect_compiler/x64-linux-rel/vcpkg-parallel-configure
    Error code: 1
    See logs for more information:
      C:\vcpkg\buildtrees\detect_compiler\config-x64-linux-out.log

Call Stack (most recent call first):
  scripts/cmake/vcpkg_configure_cmake.cmake:319 (vcpkg_execute_required_process)
  scripts/detect_compiler/portfile.cmake:18 (vcpkg_configure_cmake)
  scripts/ports.cmake:128 (include)

Error: vcpkg was unable to detect the active compiler's information. See above for the CMake failure output.

This is not a surprise as I don't expect it to be able to build packages targeting Linux on my Windows machine.

I'm new to cross-platform development and I find documentation on vcpkg + WSL rather sparse. Am I right in assuming that the packages should be installed by vcpkg running on the Linux system? Or do I need to have CMake setup on Windows to make vcpkg work on the Windows side?

Setup:

  • Windows 10 Build 19041
  • Visual Studio 2019 (16.8.5) with Visual C++ for Linux Development
  • Ubuntu 20.04 LTS as WSL
  • vcpkg commit f226416d2
uvbkq
  • 101
  • 1
  • 7

1 Answers1

3

It seems that I was a bit off track.

vcpkg installed on the Windows machine is accessible on the Linux system the same way as the actual CMake project is accessible. Setting the "CMAKE_TOOLCHAIN_FILE" variable to the absolute "C:/vcpkg/scripts/buildsystems/vcpkg.cmake" path gets translated into "/mnt/c/vcpkg/scripts/buildsystems/vcpkg.cmake".

The missing step was to run the ./bootstrap-vcpkg.sh script on the Linux system to make sure packages can be installed by vcpkg on the Linux system.

I also learned that packages have to be installed manually by running the vcpkg install command since there is no "build in" way to do this via CMake.

uvbkq
  • 101
  • 1
  • 7
  • 3
    > I also learned that packages have to be installed manually by running the vcpkg install command since there is no "build in" way to do this via CMake. Not true, see: https://vcpkg.readthedocs.io/en/latest/specifications/manifests/ (this also automatically runs bootstrap) – Alexander Neumann Feb 12 '21 at 11:24