0

I know the similar question to this, this ain't it; although my case is extremely similar. The first 4 lines of the Code::Blocks "Hello World" program when you open a new GTK project are this:

#include <stdlib.h>
#include <gdk/gdk.h>

static void helloWorld (GtkWidget *wid, GtkWidget *win)

And the compiler build log goes as follows (with every instance of the type flagged, I only inlcuded the first for brevity):

-------------- Build: Debug in graphics project (compiler: GNU GCC Compiler)---------------

gcc -Wall -g -I/usr/include/gtk-4.0/ -I/usr/include/glib-2.0/ -I/usr/lib64/glib-2.0/include/ -I/usr/include/cairo/ -I/usr/include/pango-1.0/ -I/usr/include/harfbuzz/ -I/usr/include/gdk-pixbuf-2.0/ -c "/home/********/Documents/graphics project/main.c" -o obj/Debug/main.o
gcc  -o "bin/Debug/graphics project" obj/Debug/main.o    
/home/********/Documents/graphics project/main.c:4:25: error: unknown type name ‘GtkWidget’
    4 | static void helloWorld (GtkWidget *wid, GtkWidget *win)
      |                         ^~~~~~~~~

What?!? The GTK documentation states that 'GtkWidget' is the base class for darn near everything. I frankly don't know how this is possible. By way of explanation, the one thousand and one -I (as in India) directories here are because for some reason when I installed the GTK4 toolkit via command line, it put quite a few dependencies inside sub folders in the /usr/include/ directory and of course you can't tell the compiler to search all sub folders. The specific command I used to install GTK was

sudo yum install gtk4-devel

and I'm on Fedora 35 workstation running Code::Blocks version 20.03 and gcc-c++-11.2.1-9.fc.35.x86_64, if any of those things make a difference here. I even uninstalled GTK4 and reinstalled it, just to see if that would fix it--nope. I'm very new to programming in general and GUIs in particular, and I basically just wanted to screw around with the "Hello World" program without any specific goal in mind. I just want to learn. But this sort of thing has given me unending grief since minute one of trying to learn programming, and this time I can't Google the answer. Oh well, first time for everything.

owl
  • 3
  • 3
  • You set the include and library path with `pkg-config`, e.g. generally `\`pkg-config --cflags --libs gtk4\`` You can simply run that at the command line and it will spit out the configuration. That is generally included in the Makefile for that purpose. Hope you have better luck making gtk4 look presentable than I did. Bland... – David C. Rankin Apr 16 '22 at 04:51
  • Thank you so much for that command @DavidC.Rankin Adding all the search directories one by one after searching for it in the /usr/include/ file vis-a-vis the file manager was a pain in the ass. And you're right, GTK seems to be a little bland, I wonder what would cause that? – owl Apr 18 '22 at 22:55
  • Gtk4 now depends on libadwaita, writing the default CSS theme Adwaita into the toolkit instead of just gnome desktop. With the CSS theming verses the traditional gtk2/metacity themes, there are very very few to choose from. Hopefully that will change, but I'm not holding my breath `:)` – David C. Rankin Apr 19 '22 at 02:11

1 Answers1

1

I have been predominantly using Code Blocks for some time now on various GTK3 and GTK4 projects. I have also done some tweaking of the IDE as it pertains to building a GTK3 or GTK4 project, so in order to remember what a "vanilla" GTK project looked like with Code Blocks, I installed the IDE on a virtual Linux Mint machine and launched a new project. As with you, selecting "GTK" as my project type, the IDE generated a boilerplate "Hello World" program in the "main.c" file. However, I noticed one difference right away between the code generated on my machine and your example above. There is a difference in the "include" file set. Your set has the following:

#include <stdlib.h>
#include <gdk/gdk.h>

static void helloWorld (GtkWidget *wid, GtkWidget *win)

On my machine the first three lines of code are as follows:

#include <stdlib.h>
#include <gtk/gtk.h>

static void helloWorld (GtkWidget *wid, GtkWidget *win)

If indeed, your version of Code Blocks is referencing the GDK library (which contains information for objects such as cairo information and not the widget information), you may want to revise your reference to "include" file <gtk/gtk.h>. The other thing to note is that in the "vanilla" version of Code Blocks, the version of GTK that version 20.03 of Code Blocks references GTK2 libraries and configurations for the build process. If you happen to open the build information for the project, you are probably going to see a build setting such as the following under "Other Compiler Options":

`pkg-config gtk+-2.0 --cflags`

And, under linker options, you will probably find a library setting such as the following:

`pkg-config gtk+-2.0 --libs`

Due to that fact, your code probably won't compile if do not have the GTK2 libraries on your system. Linux Mint does have the GTK2 libraries installed by default. I do not know if Fedora does that.

So for your initial "Hello World" project and subsequent projects, you could probably just revise the "include" file reference to <gtk/gtk.h> and see if the program will build.

I hope that explanation clarifies things for you.

Regards.

NoDakker
  • 3,390
  • 1
  • 10
  • 11
  • Ah, yes, I must've deleted the #include and then retyped it with imperfect memory. Funny that gdk exists right beside gtk so I could screw up, then "fix" my problem just enough to not be able to notice what's going on. Also, fedora does seem to include GTK2 by default, because the first thing I do when I boot a live disk is run 'gsettings set og.gnome.desktop.interface gtk-theme Adwaita-dark' Or maybe that installs GTK2, I have no idea. – owl Apr 18 '22 at 22:01