I have successfully configured Visual Studio to build my CMake/C++ project in a modified WSL and deploy the resulting binary to my target hardware (embedded device) for debugging. I am cross-compiling both from Windows to Linux and from x86 to ARM.
This all works fine, including breadkpoints and all that.
But now, no matter what I try, Intellisense cannot find most of the headers anymore and behaves inconsistently, as if running into an error state.
While the build process can, it seems Intellisense cannot handle the modifications I made to WSL (installing Yocto SDK and sourcing its variables automatically), because for a default WSL (without the SDK) Intellisense for a hello world program works just fine
as well.
Unable to find the root cause, I tried to manually add an include path in different ways, but to no avail:
- Various options in "CMakeSettings.json" including "intellisenseOptions" and "intellisenseMode"
- Creating a "CppProperties.json" with appropriate path information in "includePath"
- Soft-linked SDK-Headers to "/usr/include"
- Changed SDK-Flags for compiler/linker in case Intellisense can't handle them
I managed to get Visual Studio to correctly copy all needed Headers into the local Cache (~\AppData\Local\Microsoft\Linux\HeaderCache\1.0\wsl_wsl\), but in Visual Studio these headers (project specific and system) still cannot be found by Intellisense.
I tried to inspect what Visual Studio does in the background by activating verbose logging:
- Visual Studio Options -> Text Editor -> C/C++ -> Advanced -> Diagnostic Logging: True, 5, 8
- Visual Studio Options -> CMake -> General -> Internal CMake Logging: True, Verbose
The output in both logs is unintelligible for me and makes little sense.
Intellisense lists "/ClangMode" and various include paths as command line options. Those include path in the log do seem to be the ones IntelliSense is running with, because headers in those path can be auto-completed in the editor. But I can not
track down where it derives these options/paths from and they are not configured in the iconfig.json that is automatically generated in the CMake build directory.
In the CMake log "Cross Platform Logging" I stumbled across a trace output as if an exception was thrown:
17:28:06.0279765 [Debug, Thread 68] Microsoft.VisualStudio.Workspace.ExternalBuildFramework.Impl.Services.BuildProjectScannerService: GetScanToken: at Microsoft.VisualStudio.Workspace.ExternalBuildFramework.Impl.Services.BuildProjectScannerService.GetScanToken(String root, Guid providerGuid)
at Microsoft.VisualStudio.Workspace.ExternalBuildFramework.Impl.Services.BuildProjectScannerService.<ScanContentAsync_Impl>d__50`1.MoveNext()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
[...]
at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
Again, I can make no sense of it, but with time and frustration I started to suspect that IntelliSense - or something else in the background - runs into an exception and can thus not execute correctly.
But is it due to an error in my configuration or due to a bug in Visual Studio? My configuration is sufficiently correct for VS to build and deploy my program so what stops IntelliSense from working the same way?
Because I am using CMake, Visual Studio / IntelliSense should be deriving all needed options automatically and an iconfig.json is generated and found correctly. Where do I get more information on what is (not) going on in the background?
My problem is rather specific, but maybe someone has had a similar experience or could point me in the right direction for how to solve the issue. Any tip is appeciated!