You are not logged in.
Pages: 1
[SOLVED]
Hello, I've been trying to learn GTK but I'm having an issue where including GTK in my C source file doesn't work properly,
I did
sudo pacman -S gtk4 So I included this in my code
#include <gtk-4.0/gtk/gtk.h> But the compilation fails and that's the output:
In file included from example.c:1:
/usr/include/gtk-4.0/gtk/gtk.h:30:10: fatal error: gtk/css/gtkcss.h: No such file or directory
30 | #include <gtk/css/gtkcss.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
Edit: Using gtk3 instead worked
Last edited by rynite (2022-09-05 15:39:13)
Offline
That's not the correct way to include GTK headers. Instead, you should append the output of `pkg-config --cflags gtk+-4.0` to your CFLAGS.
Offline
Thanks for replying, but how is that please?
I ran `pkg-config --cflags gtk+-4.0`, and the output is
Package gtk+-4.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-4.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'gtk+-4.0', required by 'virtual:world', not found
Edit: I understood what you mean, but the output looks like an error to me.
Last edited by rynite (2022-09-02 11:39:06)
Offline
That would be gtk4.pc - I don't have it installed and just assumed it would follow the same format as gtk3
Offline
Then once you use pkgconf (ideally in a Makefile) your include line could then just be:
#include <gtk/gtk.h> While your current include line will work on an arch linux system* it may not be portable to other distros or OSs. Using just gtk/gtk.h will allow it to be more portable as other systems may have these headers in different paths (and this will then be handled properly by pkgconf / pkg-config).
* note: so long as the right -I and lib flags are passed which is what pkgconf does for you)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I ran `pkg-config --cflags gtk+-4.0`, and the output is
Shouldn't that be something like:
gcc file.c -o file $(pkg-config --cflags --libs gtk+-4.0)Offline
That would be gtk4.pc - I don't have it installed and just assumed it would follow the same format as gtk3
How can I get gtk4.pc?
Offline
I actually solved the issue by just using GTK3 instead, thanks everyone for helping
Offline
You can get the necessary include flags with pkg-config --cflags --libs gtk4 and if you really want to do manual includes rather than a proper makefile, you can look at the paths that command outputs to know what you should actually pass.
Doing new development on a old library doesn't sound like a good idea, especially for such a trivially fixable mishap.
Last edited by V1del (2022-09-05 15:46:05)
Offline
How can I get gtk4.pc?
Where did you get gtk4?? The gtk4 package in the repo comes with the .pc file.
It sounds like the problems here aren't at all about the libraries or even your code, but rather a lack of understanding on how to use pkgconf / pkg-config. If you are writing software that uses system libraries you should learn a bit about this.
Last edited by Trilby (2022-09-05 16:34:14)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Pages: 1