I use coc and coc-clangd for C/C++. When I want to use gtk I get this message: enter image description here

When I compile the file with command below, the process completes successfully.

gcc `pkg-config --cflags gtk+-3.0` -o main main.c `pkg-config --libs gtk+-3.0`

Why I get this error?

More info:

OS: Debian

Editor: NeoVim


1 Answer 1


tl;dr: You need to tell clangd how your project is built and where to find (non-standard) libraries, source files and headers etc., by generating compile_commands.json or similar.

When using language servers, clangd in this case, it needs to be told how the project is built. This includes, but is not limited to, compiler flags, linked libraries (and versions), header files in non-default locations, compiler, compiler version etc. Language servers for newer languages often just work™, but being C, the level of magic is low and you're expected to provide this info/configuration.

A widely adopted and supported way is to generate a compile_commands.json file. Tools such as CMake support generating this file automatically for you, but it can also be generated manually (although I'd advice against it since it doesn't scale very well).

  • 1- Library that I used is in the standard libraries' path. Problem is this: I should use pkg-config --cflags --libs gtk+-3.0 when I compile and clangd does not use it when compiling so sends this message. How can I resolve this? 2- Can you send a sample compile_commands.json? 3- I updated question's picture Commented Jan 27, 2022 at 19:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.