Closed ZZH-Finalize closed 3 months ago
The flag can be removed using https://clangd.llvm.org/config.html#remove if clang does not recognize it.
The flag can be removed using https://clangd.llvm.org/config.html#remove if clang does not recognize it.
I add this configuration to my .clangd file, the error is gone but I still can't get any tip or code completion at all.
But I noticed that if I use bear to generate the compile_commands.json, the clangd will work as expected, the compile flags are the same. The only difference between these two "compile_commands.json" is the format, "meson" put flags into command section but "bear" put flags into arguments section like this:
Can you share a complete clangd log for the non-working (meson) case?
Yes, I setup a new demo project that doesn't contain any confidential information, this project has the same problem. I uploaded the"compile_commands.json" file and clangd log. compile_commands.json clangd.json clangd-log-from-vscode-output.txt dot_clangd.txt
The relevant error from the log seems to be:
E[15:41:12.622] Could not build a preamble for file /workspace/proj/riscv-demo/src/main.c version 1: CreateTargetInfo() return null E[15:41:12.622] error: unknown target CPU 'rv64imafdc_zicsr_zifencei_zba_zbb'
Suggesting the flag -march=rv64imafdc_zicsr_zifencei_zba_zbb
is the problem. Try removing that one too?
(I don't have a log for the working (bear) version to compare, but maybe that one doesn't have this flag?)
(I don't have a log for the working (bear) version to compare, but maybe that one doesn't have this flag?)
I can provide that also, and I can upload another version clangd log which without -march flag (by add configuration to .clangd file, instead of remove flags from the build system).
Both of them will work as expected. But bear version have -march -mabi flags, meson version doesn't have those flags.
bear version: compile_commands.json clangd.json clangd-log-from-vscode-output-bear.txt
meson version without -march: compile_commands.json clangd.json clangd-log-from-vscode-output-without-march.txt
A potentially relevant difference is that with bear
, the command contains --target=riscv64-unknown-elf
, so clang doesn't need to look at the -march
to try to determine the target.
Anyways, it sounds like you've got it working.
Yes, thanks for the help.
I have to say I made a mistake that I forgot the compiler is different between the meson case and the bear case.
And I noticed that all of these three configurations will work, so here is the question, does clangd parse the name of compiler to get target information? When I set the compiler to riscv64-unknow-elf-gcc
, It could work with the -mabi -march
flags, but when I set it to riscv-none-elf-gcc
it will not work because of clangd couldn't get the correct target information from compiler name, then it tries to parse the -march -mabi
flags and met another error. Is that correct?
Yes, clangd tries to infer the target by parsing the compiler executable name (that happens here in the code).
clangd raise an error "Unsupported option '-mabi=' for target 'x86_64-unknown-linux-gnu'" after I rebuild my project, but it works well before.
I have already specified the '-mabi=lp64d', and this flag is generated to compile_commands.json by meson build system.
![image](https://github.com/clangd/vscode-clangd/assets/33342565/b47a8e4b-92e3-4a26-83af-3cb7837e0f32)
System information Clangd version (from the log, or
clangd extension version:
Operating system:
![image](https://github.com/clangd/vscode-clangd/assets/33342565/4a83b28e-825c-4c76-8fcc-b656ec43bfce)
clangd --version
):