Vscode-cpptools: Configuration - cl.exe installed with 'Build Tools for Visual Studio' not detected

Created on 6 Feb 2020  路  12Comments  路  Source: microsoft/vscode-cpptools

I am following the instructions in https://code.visualstudio.com/docs/cpp/config-msvc
When I get to step 2, in the Compiler Path box I see a red "(No compiler paths detected)"
From the command prompt, cl.exe is definitely on the path.
I can set it manually in the c_cpp_properties.json - should be C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.24.28314\bin\HostX64\x64 - but the docs imply that the extension should be able to pick this up automatically.

VS Code version: 1.41.1
C/C++ extension version: 0.26.3
Compilers: Visual Studio 2019 Developer Command Prompt v16.4.4
(not installed Visual Studio, just the command line tools)

Configuration Language Service bug fixed (release pending)

Most helpful comment

The bitness of the compiler shown doesn't currently have any effect for cl.exe in regards to IntelliSense, which can have its bitness changed via the msvc-x64 or msvc-x86 intelliSenseMode settings.

All 12 comments

Hi @pedro-w . It looks like you are using "Build Tools for Visual Studio 2019", and do not have Visual Studio 2019 (Preview) installed. Is that correct? If so, it looks like we may not be detecting the install location for Build Tools correctly.

@Colengms yes, correct, it was "Build Tools for Visual Studio 2019" from https://visualstudio.microsoft.com/downloads/#other

I was trying to see if I could help diagnose the cause myself but I can't find where in the code it actually looks for the compilers. I assume it's something to do with the knownCompilers property?
I have downloaded the latest code from this repo and am able to rebuild/debug it in VS code. Any hints as to where to start?

Yeah, if you don't see the build tools for VS in the knownCompilers, then it's not being found by our closed source language server component.

I thought I was losing my marbles when I couldn't find the code for setting knownCompilers! Anyway please let me know if I can provide any more info to help.

Hi @pedro-w . I'm having trouble repro'ing this. I created a fresh VM (without VS), installed the VS 2019 Build Tools (with C++ Build Tools checked), opened a new folder in VS Code (with no c_cpp_properties.json), opened a .cpp file to trigger the C++ Extension (v0.26.3) to start up. Then I ran the command C/C++: Edit Configuration (JSON), and saw that it populated a newly created c_cpp_properties.json with the proper compiler path. Could you try the above, and see if you get the same results?

Attempting the above and selecting C/C++: Edit Configuration (UI) instead also appeared to populate the correct compiler path.

Compiler detection is done in our native exe. We iterate through all directories found under the following path: %ProgramData%\Microsoft\VisualStudio\Packages\_Instances . Within each of those directories, we open state.json, and look for installationPath. We add \VC\Tools\MSVC to that path, and look for a folder there containing a version number (only '.' and numbers). Within that folder we expect to find folders named "include" and "bin". We expect to find bin/Hostx64/x64/cl.exe and/or bin/Hostx86/x86/cl.exe . Can you confirm whether there is anything that might be blocking any of these steps?

I'll check the fresh install stuff but it might take me a while to set up a VM etc.

I can say straight away that I don't have the _Instances path that you mentioned. I guess this is the reason why your server can't find the file?

>echo %ProgramData%
C:\ProgramData
>dir %ProgramData%\Microsoft\VisualStudio\Packages\
 Volume in drive C is OS
 Volume Serial Number is 2ABE-6EC2

 Directory of C:\ProgramData\Microsoft\VisualStudio\Packages

14/11/2018  08:57    <DIR>          .
14/11/2018  08:57    <DIR>          ..
06/02/2020  08:52    <DIR>          _bootstrapper
06/02/2020  08:59    <DIR>          _Channels
               0 File(s)              0 bytes
               4 Dir(s)  29,392,039,936 bytes free

I have installed and uninstalled Visual Studio 2019 Community in the past and maybe that has caused some confusion in the configuration.
Anyway if I can get a fresh VM set up that will hopefully point us in the right direction.
Thanks for your help.

OK I have made some progress. I installed VS code and the Build tools on a real Windows 10 PC which had never had either on before. Everything worked as you describe. I saw that %ProgramData%\Microsoft\VisualStudio\Packages contained a whole bunch of directories named after packages (I assume) as well as the _Instances directory.

Back on my PC, I found another path on my D: drive (I've got a small SSD C: and a larger HDD D:) which was D:\ProgramData\Microsoft\VisualStudio\Packages and in here I found the _Instances and all the other stuff.

It's quite likely I told the VS installer at some point to put stuff on D:\ because my C:\ drive was getting full.

The VS Installer itself seems to be OK with this (and the tools themselves are actually installed to C:) so I don't know if this is in their remit to change or yours?

Anyway it's not difficult just to set the compiler path manually, though having just gone through the 'automatic' process on a fresh PC, it's really impressive how straightforward you've made it. Thanks!

[edit]
I found this path in the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\Setup\CachePath

with the value

D:\ProgramData\Microsoft\VisualStudio\Packages

so maybe you should be looking in there?

@pedro-w . Thanks for digging into this. I think you are absolutely correct.

I have installed the insiders release and am happy to report that the drop-down now contains the correct path to the compiler. I was able to follow the "Configure VS Code for Microsoft C++" article that I mentioned above from beginning to end. Thanks for your help with this!

Quick question - since I also have the MSVC 32-bit compilers and the cross compilers installed, I would have expected them to be in the drop-down too, but only the 64-bit native compiler was listed. Is this what you would expect?

The bitness of the compiler shown doesn't currently have any effect for cl.exe in regards to IntelliSense, which can have its bitness changed via the msvc-x64 or msvc-x86 intelliSenseMode settings.

Was this page helpful?
0 / 5 - 0 ratings