#clangd 'gtk/gtk.h' file not found

9 messages · Page 1 of 1 (latest)

cobalt charm
#

So, I'm trying to use clangd for the first time, I did however get the same errors with ccls, so it's probably something about my setup which is wrong.

This is my only C file, which contains the GTK example code:

#include <gtk/gtk.h>

static void print_hello (GtkWidget *widget,
             gpointer   data)
{
  g_print ("Hello World\n");
}

static void
activate (GtkApplication *app,
          gpointer        user_data)
{
  GtkWidget *window;
  GtkWidget *button;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

  button = gtk_button_new_with_label ("Hello World");
  gtk_widget_set_halign (button, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (button, GTK_ALIGN_CENTER);

  g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
  g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_destroy), window);

  gtk_window_set_child (GTK_WINDOW (window), button);

  gtk_window_present (GTK_WINDOW (window));
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

It is unable to find gtk/gtk.h even though it is installed.
If I run gcc -o main $(pkg-config --cflags --libs gtk4) *.c the application runs, everything is perfect. But I'm unable to make use of an LSP, probably because I have configured clangd wrong.
I have a compile_flags.txt, but I'm not even sure what to put into it. The documentation for clangd and ccls configuration is very vague.

I'm on Linux, if that's relevant.

fluid hillBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

outer laurel
#

compile_flags.txt is very simple, you just put the flags you would give to the compiler. You could pkg-config --cflags gtk4 > compile_flags.txt and get a starting point

#

I can't remember if 1 flag per line is required so you might have to break it up into lines

cobalt charm
#

Thank you very much!

#

!solved

fluid hillBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity