2

Recently i've been working on some project with GNU arm compiler for C++ project. I've configured clangd to use this compiler with query-driver as clangd documentation recommends. The problem is clangd tries to use internal llvm include headers instead of compiler provided and fails.

$ from clangd logs for some system headers /path/to/compiler/aarch64-none-linux-gnu-g++ --target=aarch64-none-linux-gnu --driver-mode=g++ -v -c -x c++-header -resource-dir=/usr/lib/llvm-14/lib/clang/14.0.0 -- /path/to/tompiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/lib/gcc/aarch64-none-linux-gnu/11.3.1/include/arm_neon.h 

As it can be seen clangd sets resource-dir as if it was not compiled with my compiler.

Also there is problem with found headers. Clangd produces following search paths.

#include "..." search starts here: #include <...> search starts here: /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1/../../../../aarch64-none-linux-gnu/include/c++/11.3.1 /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1/../../../../aarch64-none-linux-gnu/include/c++/11.3.1/aarch64-none-linux-gnu /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1/../../../../aarch64-none-linux-gnu/include/c++/11.3.1/backward /usr/lib/llvm-14/lib/clang/14.0.0/include /usr/local/include /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1/../../../../aarch64-none-linux-gnu/include /usr/include End of search list. 

Calling compiler directly provides more include paths without llvm includes.

$ my_compiler -v -c -xc++ /dev/null #include "..." search starts here: #include <...> search starts here: /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1/../../../../aarch64-none-linux-gnu/include/c++/11.3.1 /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1/../../../../aarch64-none-linux-gnu/include/c++/11.3.1/aarch64-none-linux-gnu /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1/../../../../aarch64-none-linux-gnu/include/c++/11.3.1/backward /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1/include /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1/include-fixed /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/11.3.1/../../../../aarch64-none-linux-gnu/include /path/to/compiler/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin/../aarch64-none-linux-gnu/libc/usr/include End of search list. 

How can i fix this? Clangd version - 14.0.0

1 Answer 1

1

In clangd 21 and later, you can use the BuiltinHeaders config file option by creating a .clangd config file containing:

CompileFlags: BuiltinHeaders: QueryDriver 

Please note the following caveat listed in the documentation:

Note: if the driver is not clang, BuiltinHeaders: QueryDriver will result in the clang frontend (embedded in clangd) processing the builtin headers of another compiler, which could lead to unexpected results such as false positive diagnostics.

The bottom line is that clangd is a clang-based tool, and compatibility with non-clang compilers is never going to be 100% perfect (but the option listed above may improve accuracy in some situations, maybe including yours).

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

2 Comments

So it's not possible to fix this problem without updating to clang-21?
A way to do it in earlier versions would be to add the missing include path using clangd.llvm.org/config.html#add. That said, I highly recommend running an up to date version of clangd. Clangd 14 is almost 4 years old, and a lot of bugs have been fixed and improvements made since then. Recent versions of clangd can be obtained from github.com/clangd/clangd/releases.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.