Search code examples
visual-studiovcpkg

Installation of VCPKG followed by any call to "vcpkg install" results in "Changing the working dir failed"


When I follow the steps in the VCPKG documentation page to install on Windows, the noted steps fail on the line .\bootstrap-vcpkg.bat.

Specifically, these are the steps I follow, exactly according to the instructions at the above link.

  • Run Powershell (not as administrator)
  • cd <parent_directory>
  • git clone https://github.com/Microsoft/vcpkg.git
  • cd .\vcpkg\
  • .\bootstrap-vcpkg.bat
  • .\vcpkg integrate install

All above steps (seem to) succeed, until the last (in red, below).

I see the following output:

"Changing the working dir failed"

(Note: the screenshot also shows an additional line at the end - in which I attempted to install a desired package for use in a project - which failed with the same error.)

I looked through the source code of vcpkg and found that the offending line of code looks like this (vcpkg.cpp):

enter image description here

Modifying the vcpkg.cpp source to display the missing path, rebuilding, and testing shows that the missing directory is:

<vcpkg>/installed/...

...But the installed directory does not exist in the vcpkg root directory.

Because I am following the basic installation instructions from the vcpkg documentation, I'm stumped as to what I am doing wrong, what is wrong in my setup, or what to do about it.

Can someone please explain why installation of VCPKG followed by any call to "vcpkg install" results in the error Changing the working dir failed?


Solution

  • I had mistakenly defined the VCPKG_ROOT environment variable to a directory that is a subdirectory of the root directory of the vcpkg project.

    This is an easy mistake to make, as I describe below.


    The vcpkg executable itself checks for the existence of the VCPKG_ROOT environment variable, and if present, uses its value to override the path to the root folder for the vcpkg project that is used internally by the running vcpkg binary.

    I created an environment variable with the same name (VCPKG_ROOT) for a different purpose - so that my own downstream application could be provided the path to the include files for a library installed by vcpkg. It makes sense that I would choose the name VCPKG_ROOT, because in fact vcpkg, by default, installs libraries into a subdirectory of its own root directory.

    Specifically:

    • If the root directory of the 'vcpkg' project is <vcpkg>...
    • ...then by default the vcpkg executable installs libraries such that the include paths for the libraries that are installed are placed in <vcpkg>\installed\...\include\

    (And other library files, such as binaries, are also placed in directories nested within <vcpkg>.)

    The problem was that I defined VCPKG_ROOT to be the second bullet, not the first. So it's an easy mistake to make, given that the choice of name "VCPKG_ROOT" kind of makes sense in both scenarios!

    I just suggested an improved error message via a pull request to the vcpkg project - if accepted, this might save some other poor soul the stress and lost time of tracking down this glitch.