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?
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 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
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’.)
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.