Cross compiled gcc make project and clangd


I am trying to get clangd to work for a project that is cross compield to various targets. Using GCC and regular Makefiles.

First I tried to generate compile_commands.json with “compiledb” project from github.
It generates the filesok, but clangd gets into trouble mixing up stdlib from clang and gcc it seems.

Then I tried with a compile_flags.txt instead and get it to work decently if omitting all references to the sysroot to the cross compile target.

But then it seems the clangd indexer requires compile_commands.json, right?

So is there any recommended way to handle cross_compiled gcc make projects?
I have tried various combinations of these flags:

But there is always some problems like std lib headers not found or c++17 features not recognized or differences in stdlib messing it up.

So should it be possible to make a cross compile SDK (gcc) work with clangd?

Perhaps an option for me is to generate compile_commands.json and the filter out all references to the SDK?



Hi Daniel,

You should try using “bear” for compiler database generation, it works pretty well.

In addition you need to tell clangd to query the compiler for the system header.
Look for the --query-driver option in the manual.


or a newer one

more handy as it can parse build log file directly without rebuilding the project.


compiledb -S -p build_log.txt