MacPorts did not install gtk.h

I used MacPorts to install gtk on my MacBook Pro, but when I try to run a small program in XCode, I get an error that gtk/gtk.h is not found. When I search my hard drive for gtk.h, it is not found. Two questions:
(1) Why did MacPorts not include gtk.h on my system?
(2) Is there a site where I can download gtk.h?

Any help greatly appreciated!

Sounds like a question for MacPorts :slight_smile:

I will ask there, thanks.

I have the port gtk3 installed and it provides the file gtk.h. On my system:

xxx-xxxxx-xxxxxxx-xxx:~ xxxxxx$ port installed | grep "gtk"
Warning: port definitions are more than two weeks old, consider updating them by running 'port selfupdate'.
  gtk3 @3.14.9_0+x11
  gtk3 @3.22.30_0+x11
  gtk3 @3.24.12_0+x11
  gtk3 @3.24.21_0+x11
  gtk3 @3.24.23_0+x11 (active)
  gtksourceview3 @3.14.3_0
  gtksourceview3 @3.24.8_0
  gtksourceview3 @3.24.11_0
  gtksourceview3 @3.24.11_1 (active)
xxx-xxxxx-xxxxxxx-xxx:~ xxxxxx$ port contents gtk3 | grep "gtk\.h"
Warning: port definitions are more than two weeks old, consider updating them by running 'port selfupdate'.
  /opt/local/include/gtk-3.0/gtk/gtk.h
  /opt/local/share/gtk-doc/html/gtk3/gtk.html
xxx-xxxxx-xxxxxxx-xxx:~ xxxxxx$ ls /opt/local/include/gtk-3.0/gtk/gtk.h
/opt/local/include/gtk-3.0/gtk/gtk.h

Which port are you using? What do the above command report for you?

I installed the latest MacPorts Mac OS distribution.

When I try:
sudo ls /opt/local/include/gtk-3.0/gtk/gtk.h
/opt/local/include/gtk-3.0/gtk/gtk.h

I get this:
zsh: permission denied: /opt/local/include/gtk-3.0/gtk/gtk.h

When I run:
% sudo port selfupdate

I get this:
—> Updating MacPorts base sources using rsync=
MacPorts base version 2.7.2 installed,
MacPorts base version 2.7.2 downloaded.
—> Updating the ports tree
—> MacPorts base is already the latest version

If you actually entered

sudo ls /opt/local/include/gtk-3.0/gtk/gtk.h
/opt/local/include/gtk-3.0/gtk/gtk.h

in a terminal, the second line is trying to execute the header file, hence permission denied. Sorry if my message above wasn’t clear - the commands I entered are on the lines following a ‘$’. The subsequent lines are the responses echoed back. What does
ls /opt/local/include/gtk-3.0/gtk/gtk.h
report?

(I think the file must be there, as otherwise you would have got the message ‘file not found’ instead of ‘permission denied’.)

Yes, the file is there. It was just hard to find. I had to tell Finder to show all files, even ones normally hidden.

To solve your original issue, it sounds like Xcode doesn’t have the right CFLAGS to find gtk.h. If you build from the terminal, then you can get the long list of flags using pkg-config - see Gtk – 3.0: Compiling GTK Applications.

It would be painful to copy these flags manually. It looks like you are not the first:

On Mac systems, I’ve only ever built from the terminal (creating my own Makefile for anything non-trivial) so don’t know about using Xcode.

cc pkg-config --cflags gtk+-3.0 hello-gtk.c -o hello-gtk pkg-config

gives me this result:

In file included from hello-gtk.c:1:

/opt/local/include/gtk-3.0/gtk/gtk.h:57:10: fatal error: ‘/opt/local/include/gtk-3.0/gtkcellareabox.h’ file not found

#include </opt/local/include/gtk-3.0/gtkcellareabox.h>

It seems every dependency in gtk.h needs the full path, not just gtk/*.h

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.