Mostly because very few people actually use macOS, XCode, and GTK.
The few that do are mostly working on Linux apps and porting them to macOS, which means they know how to use a toolchain, and they don’t use XCode at all. Various free and open source applications use jhbuild on macOS; but, again: those are actual applications, typically developed on other platforms.
GTK on macOS builds every dependency it can, and can be used as a Meson subproject for your own project; of course, that assumes you’re actually writing a project. It does not work if you’re trying to compile a single file “Hello World” example.
I’ve decided to abandon gtk as a realistic solution to my GUI needs. I wish to thank all those who took the time and effort to assist me in this forum! You are a valuable resource!
I will eventually port my app to Java which has built-in GUI capabilities.
I think you’ve snatched defeat from the jaws of victory here From the discussion above, it looks like you removed the MacPorts installation just before using the correct build command with the correct #include in your source.
You are learning some new concepts at the same time. As you weren’t familiar with using a terminal, communication has been harder and documentation assumes familiarity with using a terminal.
It is recommended that a beginner installs a package on their system using a package manager. You did that initially with MacPorts (you could have used Brew). Unfortunately you went ‘upstream’ to GTK, using gtk-osx-build-setup.sh. If you go upstream to the source projects, you have to build the project yourself and there is usually more complexity. In this case, the jhbuild setup was likely not providing you with the environment you expected. I would recommend beginners use package managers if possible.
Also, some general points to help you diagnose issues in other forums if not here. All should be taken constructively.
Don’t assume what is wrong, state what you were trying to achieve. For example you assumed that MacPorts didn’t install gtk.h and most people would think they couldn’t help you. However, MacPorts had installed it and others could have helped as that wasn’t the issue.
If you quote the following in your message:
source file
the command you used to build it
the error message you received
then most people here would likely be able to quickly point out what is wrong. You should include these verbatim. In this discourse forum that is achieved by putting the contents inside triple backtick markers e.g.
Another problem was the title of the topic referencing “your” hello world program. It’s quite unlikely that anybody involved with GNOME would write a hello world that begins with #include </opt/local/include/gtk-3.0/gtk/gtk.h>. Surely that’s really your own…
You’ve missed off the ccat the start of the command. It should be
cc `pkg-config --cflags gtk+-3.0` hello-gtk.c -o hello-gtk `pkg-config --libs gtk+-3.0`
Also
zsh: no such file or directory: -I/opt/local/include/gtk-3.0
/opt/local/... is typically the path used by MacPorts so it looks like MacPorts is still there. Did you entirely uninstall MacPorts before installing Brew or are you aware how to use both on your system? If so, that’s fine. If not, you must use either MacPorts or Brew. Do not mix them as it won’t work. (By all means use Brew but I won’t be able to help with any Brew issues as I don’t use it.)
I deleted the /opt/local/include/gtk-3.0 directory.
When I just ran cc pkg-config --cflags gtk+-3.0 hello-gtk.c -o hello-gtk `pkg-config --libs g
I got this:
cc pkg-config --cflags gtk+-3.0 hello-gtk.c -o hello-gtk pkg-config --libs gtk+-3.0
Package gtk±3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk±3.0.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘gtk±3.0’ found
Package gtk±3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk±3.0.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘gtk±3.0’ found
2022-04-22 03:23:38.224 xcodebuild[8753:109784] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2022-04-22 03:23:38.225 xcodebuild[8753:109784] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
hello-gtk.c:1:10:fatal error:‘gtk/gtk.h’ file not found
Why? The directory hierarchy under /opt/local is managed by MacPorts and you must never make manual changes there. All changes should be done via the port command. I don’t know what state your machine is in now. Until you remove Brew and fix your MacPorts environment (ask on a MacPorts forum - I’m not sure how) I don’t think I can help you. Once you do that, your command
cc `pkg-config --cflags gtk+-3.0` hello-gtk.c -o hello-gtk `pkg-config --libs gtk+-3.0`
should compile your code and you’ll get the complier output.
I uninstalled brew, re-installed gtk using MacPots and it appears now have gtk installed correctly!
Attempting to compile hello-gtk.c, I now get:
hello-gtk.c:23:3:error:implicit declaration of function ‘gtk_window_set_child’ is invalid in C99 [-Werror,-Wimplicit-function-declaration]
gtk_window_set_child (GTK_WINDOW (window), button); ^
1 error generated.
You can continue to use GTK 3 for learning with the GTK 3 tutorial. There is a hello world example in there. Most of what you learn would transfer to GTK 4.
I would suggest doing a Google search for ‘macports < your error message >’ as these questions have probably been asked many times before. Do you have X11 available? For example, try sudo port install xorg-server.
If you get an error about D-Bus, see this comment.