cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 vscode clangd not working under Windows with space in user folder

Mikk Leini
Senior III

I had a Windows account with a space in user folder name (between forename and surname). VScode was installed under AppData subfolder. As a result CMake generated paths like this into compile_commands.json:

"command": "C:\\Users\\MIKKLE~1\\AppData\\Local\\STM32C~1\\bundles\\GNU-TO~2\\1431_S~1.2\\bin\\AR19DD~1.EXE -DDEBUG....

Most of the things worked (compiling and debugging), but vscode highlighted that it can't find includes like these:

#include <stdio.h>
#include <assert.h>

To be correct, clangd language server couldn't find them. Absence of these headers caused further errors. But when resolving other headers like stdint.h, clangd found them from st-arm-clangd bundle folder instead of compiler folder.

The workaround was to add the very same shortened path as query driver into .vscode\settings.json:

 "--query-driver=C:\\Users\\MIKKLE~1\\AppData\\Local\\STM32C~1\\bundles\\GNU-TO~2\\1431_S~1.2\\bin\\AR19DD~1.EXE"

It solved the clangd issue temporarily until ST tools rewrote settings.json.

I thought it's the classical long path issue, but enabling long paths in Windows registry and forcing CMake to use longer paths (512 characters) did not solve it.

After removing space from my Windows user folder it started working normally.

Quick guide: Create temporary admin user, reboot, login with new user, rename user folder and update it in  registry path HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList. Expect trouble with some applications.

I don't know whether it should be solved in CMake, clangd, ST vscode toolset or just made as an installation time warning. I hope ST team decides. So far maybe it helps somebody with the same issue.

16 REPLIES 16
vincent_grenet
ST Employee

@Mikk Leini 
Thank you for the exhaustive report.
I have reproduced the issue. I am unsure about the workaround. We will investigate further.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Try Long Path Tool.

Try Long Path Tool. Thanks.

Here I found a pretty good explanation of what is happening:

https://github.com/clangd/clangd/issues/1518#issuecomment-1445647536

In conclusion,

  • we will not do a fix in our ST extensions as we want to keep the current settings.json format
  • as far as we know, there is no such option to disable CMake short path
  • as the clangd issue is already 3 years old, we will log a new ticket on our side to contribute to clangd to improve this mentioned 'plain string comparison' between the driver path found in the compilation database and the --query-driver argument, but don't expect any short term fix as this will not be on our current top priorities.

In the meantime, let me post again 2 valid workarounds for future readers:

  • set your env CUBE_BUNDLE_PATH to a short location without any space in it

OR

  • overwrite the generated clangd --query-driver arguments(s) of your .vscode/settings.json with the 8.3 short path of your compiler (same one that can be found in compile_commands.json)

Hopes this helps clear things up,

MNA

tkuzma
Associate II

The same thing happens for me on MacOS. Clang was not resolving standard libraries like stdint.h and would direct the definition to the xcode gcc compiler instead of the stm32 version. I did the same fix as above and copied over the compile_commands path into query driver in settings.json and it fixed it.

The vscode compiler bundles get installed into the "/Users/USERNAME/Library/Application Support/stm32cube/bundles/gnu-tools-for-stm32/" directory by default, which has a space in it. 
Is there a way to change the default bundle directory to one without a space? I can see the environment variables when i run "cube --help" from the project directory but I'm not sure how to change it.

Environment variables:
        CUBE_BUNDLE_PATH                -- Override local bundle repository location (/Users/USERNAME/Library/Application Support/stm32cube/bundles)
        CUBE_BUNDLE_PATH_EXTRA          -- Include extra bundles in addition to installed ones (is searched recursively)
        CUBE_BUNDLE_REGISTRY            -- URL to the online cube bundle registry
        CMSIS_PACK_ROOT                 -- Path to CMSIS Pack storage (/Users/USERNAME/Library/Application Support/stm32cube/packs)
        CUBE_CACHE_PATH                 -- Path to cache storage (/Users/USERNAME/Library/Caches/stm32cube)
        CUBE_LOG_PATH                   -- Path to log storage (/Users/USERNAME/Library/Application Support/stm32cube/logs)
        CUBE_NETWORK_MAX_REDIRECT       -- Max number of redirect to follow (10)
        CUBE_NETWORK_RETRY              -- Number of retry attempts (5)
        CUBE_NETWORK_TIMEOUT            -- Timeout for network accesses (7200000ms)
 

you can change it in command line with: 

cube --set cube_bundle_path <path>

and check: 

cube --get-current-value cube_bundle_path

 

MNA

Perfect, this fixed everything and now the settings don't get overwritten. Thanks!