You are not logged in.

#1 2022-09-02 11:01:37

rynite
Member
Registered: 2022-09-02
Posts: 13

Including GTK4

[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

#2 2022-09-02 11:27:33

arojas
Developer
From: Spain
Registered: 2011-10-09
Posts: 2,295

Re: Including GTK4

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

#3 2022-09-02 11:30:54

rynite
Member
Registered: 2022-09-02
Posts: 13

Re: Including GTK4

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

#4 2022-09-02 12:32:08

arojas
Developer
From: Spain
Registered: 2011-10-09
Posts: 2,295

Re: Including GTK4

That would be gtk4.pc - I don't have it installed and just assumed it would follow the same format as gtk3

Offline

#5 2022-09-02 12:47:05

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,497
Website

Re: Including GTK4

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

#6 2022-09-02 15:51:47

teckk
Member
Registered: 2013-02-21
Posts: 588

Re: Including GTK4

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

#7 2022-09-05 15:09:33

rynite
Member
Registered: 2022-09-02
Posts: 13

Re: Including GTK4

arojas wrote:

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

#8 2022-09-05 15:38:10

rynite
Member
Registered: 2022-09-02
Posts: 13

Re: Including GTK4

I actually solved the issue by just using GTK3 instead, thanks everyone for helping

Offline

#9 2022-09-05 15:45:25

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,300

Re: Including GTK4

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

#10 2022-09-05 16:33:13

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,497
Website

Re: Including GTK4

rynite wrote:

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

Board footer

Powered by FluxBB