9

This is probably not possible, but I still want to ask. I'm using Clangd as an autocompletion engine for VSCode. It works great, but there is one problem.

The official Windows binaries of Clang rely on MSVC standard library headers. If MSVC is not installed, Clang and Clangd complain about missing headers.

There's a flag that makes Clang use MinGW's libstdc++ (--target=x86_64-w64-windows-gnu), which I have to include in compile_commands.json.

This solution works, but it would be nice to have sensible autocomplete even without compile_commands.json.

Is there a way I can tell Clangd to assume --target=x86_64-w64-windows-gnu if there is no compile_commands.json?

6
  • I found a possible solution. When starting Clangd, the VSCode extension sends some initialization parameters to its stdin. There's an otherwise unexposed parameter (initializationOptions.fallbackFlags), that lets you specify the custom flags. Now I just need some clever way to modify it on the fly. Commented Apr 10, 2020 at 22:07
  • I am on a similar boat. Have you tried running a script that sets an environment variable, and passing that environment variable in as the flags? Commented May 19, 2021 at 21:14
  • @FranciscoAguilera I don't fully understand the idea, but now the VSC extension now lets you specify the fallback flags directly in the config, so this shouldn't be an issue anymore. Commented May 19, 2021 at 21:46
  • when you say the config do you mean the .clangd file? Or VS Code settings.json as "clangd.fallbackFlags": [ "%CLANGD_FALLBACK_FLAGS%" ],? For my purposes I need to parse flags out of a compile_commands.json entry and use those as fallback flags. Commented May 19, 2021 at 22:10
  • Yes, setting.json. "I need to parse flags out of a compile_commands.json" Oh, I see. Might not work then. I'd try to amend compile_commands.json Commented May 20, 2021 at 5:49

2 Answers 2

6

At some point after the question was asked, the VSCode Clangd extension started exposing the default flags to the config: "clangd.fallbackFlags": ["--target=x86_64-w64-windows-gnu"].

Sign up to request clarification or add additional context in comments.

1 Comment

For reference: The exact same option works when using clangd via CoC (coc-clangd) in NeoVim (presumably also regular Vim)
5

Is there a way I can tell Clangd to assume --target=x86_64-w64-windows-gnu if there is no compile_commands.json?

From clangd getting started:

compile_flags.txt

If all files in a project use the same build flags, you can put those flags one-per-line in compile_flags.txt in your source root.

Clangd will assume the compile command is clang $FLAGS some_file.cc.

Creating this file by hand is a reasonable place to start if your project is quite simple.

Just create compile_flags.txt file with --target=x86_64-w64-windows-gnu.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.