Search code examples
c++linuxvisual-studio-codegtkmanjaro

Problems Including GTK for C++ on Manjaro Linux


I've been struggling for hours to include the GTK library for manjaro in C++. I'm using VS Code, I have installed the GTK-4.0 package with the command sudo pacman -Syu gtk4 and I'm including the file /usr/include/gtk-4.0/gtk/gtk.h in my C++ program with the line #include <gtk-4.0/gtk/gtk.h>. It's throwing the error

gtk/css/gtkcss.h: No such file or directory

even though there is a file named gtkcss.h at the path /usr/include/gtk-4.0/gtk/css/gtkcss.h

I've looked all over google and I can't find anyone having the same problem, especially on the same OS. Any help is much appreciated!


Solution

  • You are missing an include path.

    Gtk requires* pkg-config to set the include path. see https://developer.gnome.org/gtk4/unstable/gtk-compiling.html

    So while you have included it with a complete path, the files inside the library still require the include path to be set. I don't know which build system you are using, but in general gtk requires something like:

    g++ $(pkg-config --cflags) -c main.cpp
    

    This will expand to the right flags to set the include path.

    *You might also do this manually by adding a -I flag. But that is prone to break if you want to compile on a different machine.