I tried your hello world program in XCode and it failed to build.
I got a “Build failed” message, but no errors were flagged in the source. Here is my code:
I’ve discovered the problem. Your file gtk.h references gdk.h, but does not include its full path.
When I try to edit gtk.h to include the full path to gdk.h, I’m told the file is locked and cannot be edited.
The path to my gtk.h is </opt/local/include/gtk-3.0/gtk/gtk.h>
To anticipate your next question, my gtk files are at that location on my HD because that’s where MacPorts installed them. I’ve tried moving them elsewhere but run into the same problem trying to build with XCode.
Wow, I’ve never seen anybody attempt to use absolute paths in include statements before. This is not advisable because nobody else will be able to compile your program unless they have everything installed in exactly the same place as you. The only correct way to include gtk.h is #include <gtk/gtk.h>. If that doesn’t work, then your build system is broken and you need to fix your include flags to point to the correct paths before proceeding further. The best way to do this is to use pkg-config, though I doubt XCode supports that: you might have to configure it manually. No clue how to do that in XCode.
The ‘$’ is not part of the command, it represents the prompt in the terminal where you enter the command. The line after the ‘$’ is not part of the command, it shows the response echoed back in the terminal. So the command to enter is the text following the ‘$’ up to the end of the line. (The copy code to clipboard button is not useful here because this isn’t code - it is a mixture of terminal input and output.)
which completed without error.
Then I followed the instruction to run
cc pkg-config --cflags gtk+-3.0 hello-gtk.c -o hello-gtk pkg-config --libs gtk+-3.0
to compile my hello-gtk.c file and I got:
hello-gtk.c:1:10: fatal error: ‘gtk/gtk.h’ file not found #include <gtk/gtk.h>
^~~~~~~~~~~
1 error generated.
The “backtick command backtick” syntax means: “execute command, and then put the output in the current command line”; I don’t know what kind of shell you’re using, so maybe that doesn’t work for you.
I also recommend reading some documentation on how to use the C compiler from the command line.
In any case, this is going to be useful up until the point when you need to start writing code with GTK; once you reach that point, using a build system like Meson will remove a lot of the complications and pain.
I don’t think the backticks were missing. It looks like Discourse treated them as markdown (a code block wasn’t used).
@dgpdx Now that you have deleted the MacPorts install of GTK, where is your gtk/gtk.h? To help you, please report the output of pkg-config --cflags gtk+-3.0 and the location of your gtk/gtk.h file.