2

Intro

I'm getting started with GTK. I chose Eclipse as IDE. Right now I am at the first page of the GTK tutorial (https://docs.gtk.org/gtk4/getting_started.html).

#include <gtk/gtk.h>
//#include <gtk-4.0/gtk/gtk.h>
//#include "/usr/lib/libLLVM-15.so"

static void
activate (GtkApplication* app,
          gpointer        user_data)
{
  GtkWidget *window;
...

I compiled with

gcc $( pkg-config --cflags gtk4 ) -o example-0 example-0.c $( pkg-config --libs gtk4 )

and it compiles and executes.

Problem

My problem is that Eclipse can't resolve #include <gtk/gtk.h> and the GTK syntax. I found some (mostly old) Questions that targeting this (I've read about to include pkg-config --libs gtk4 --cflags gtk4 to the project path - I don't know how to do that) but I was not able to solve my problem.

I've tried

Solution provided by BobMorane

adding $(pkg-config --libs gtk4 --cflags gtk4) to Project -> Properties -> C/C++ build Command line pattern

adding $$(pkg-config --libs gtk4 --cflags gtk4) to Project -> Properties -> C/C++ build Command line pattern

adding

-I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/graphene-1.0 -I/usr/lib/graphene-1.0/include -mfpmath=sse -msse -msse2 -pthread -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0  

Project -> Properties -> C/C++ build Command line pattern.

The last 3 did not change the compiler command which was:

gcc -O0 -g3 -Wall -c -fmessage-length=0  -MMD -MP -MF"example-0.d" -MT"example-0.o" -o "example-0.o" "../example-0.c"

Installing PKG-config support for Eclipse CDT 1.0.0

Replacing #include <gtk-4.0/gtk/gtk.h> with #include <gtk-4.0/gtk/gtk.h> which resulted with this error:

/usr/include/gtk-4.0/gtk/gtk.h:30:10: fatal error: gtk/css/gtkcss.h: No such file or directory

Nothing that I've tried worked. What I want to achieve

Syntax highlighting and compiling from the IDE. How to do this in Eclipse 2023-03 (4.27.0)?

What worked for me

  1. Creating a empty Meson project
  2. example-0.c from the tutorial page
  3. Creating meson.build file

my meson.build:

project('monitorUpdater', 'c') 
dependencies = [ 
  # dependency('gtk+-3.0'), 
  dependency('gtk4'), 
  dependency('openssl'), 
  dependency('X11')
]

sources = [
    'example-0.c'
]

executable('gtkTest', sources, dependencies : dependencies)

IntelliSense, building and running works.

mad_mosel
  • 35
  • 8
  • I already answered a similar question for Gtkmm [here](https://stackoverflow.com/a/62203484/6575139). Not exactly your case, but I think it could help. – BobMorane May 12 '23 at 15:42
  • Thanks a lot. Tried it but unfortunately it did not work for me. – mad_mosel May 12 '23 at 16:45

2 Answers2

2

The Pkg-config support has some strange things. I switched to a meson build. Eclipse can generate a meson project. My meson build file in project root:

project('monitorUpdater', 'c')
dependencies = [ dependency('gtk4'), dependency('openssl'), dependency('X11')]
incdir = include_directories('src/include')
subdir('src')
executable('monitorUpdater', sources, dependencies : dependencies,  include_directories : incdir )

My sources are in the src folder. This folder also contains a meson.build file:

sources = files('main.c', 'screen.c', 'udp.c','updateThread.c','timer.c' ,'settings.c')
Dig Kleppe
  • 36
  • 3
0

For using eclipse managed make: Quick (and dirty I suppose)
In terminal:

pkg-config --cflags gtk4

Copy result text with all the -I.. items in Project properties->C/C++ Build->Settings->GCC compiler->Miscellaneous->Other flags field.

pkg-config --libs gtk4

Append result to Expert settings -command line pattern in Project properties->C/C++ Build->Settings-> GCC linker.

Also add /usr/include/gtk-4.0 to C/C++ General Paths and Symbols so the editor can also find gtk headers.

After this exercise I noticed a great plugin for eclipse: Pkg-config support, to be installed from the marketplace. Just set a checkbox.....

Dig Kleppe
  • 36
  • 3
  • I've tried to follow the steps. I don't have this "Project properties-> GCC compiler->Miscellaneous->Other flags field." in my installation. I can't find "Expert settings -command line pattern in Project properties-> GCC linker" either. I have "/usr/include/gtk-4.0" in my project include folder visible (gtk-3.0 and 2.0 too). I don't have "Project properties", i have "Prpoperties", I have "C/C++ build" instead of "GCC compiler"· The rest of menu seems to have a totally different structure. Which build plugin are you using? I have C/C++ as it comes from the Eclipse C++ installation – mad_mosel Jun 13 '23 at 16:40
  • Clarified eclipse menu. The items ar for a managed make project. – Dig Kleppe Jun 15 '23 at 10:25
  • Tried it with the Makefile build. My expert settings command is ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} ${EXTRA_FLAGS} $(pkg-config --libs gtk4) . I also tried to put the output of the command. The build keeps failing, the GTK classes can not be resolved. – mad_mosel Jun 29 '23 at 09:31
  • The Pkg-config support has some strange things,, I switched to a meson build. Eclipse can generate a meson project. My meson build file in project root: project('monitorUpdater', 'c') dependencies = [ # dependency('gtk+-3.0'), dependency('gtk4'), dependency('openssl'), dependency('X11') 'code' incdir = include_directories('src/include') subdir('src') executable('IntercomUpdater', sources, dependencies : dependencies, include_directories : incdir ) – Dig Kleppe Jul 03 '23 at 14:10
  • it finally worked with a meson project. thanks a lot. building, running and syntax highlighting works now. I thought this was not going to happen anymore. thanks a lot – mad_mosel Jul 08 '23 at 21:59