Check for GTK in configure

Hi, ALL,
Is there some kind of predefined macro I can use to find if GTK+ is installed and use some predefined exported variables for CFLAGS and LDFLAGS?

Don’t want to hardcode this in the Makefile…

Thank you.

pkg-config is your friend: Gtk – 4.0: Compiling GTK Applications on UNIX

@jensgeorg ,
You probably didnt understand my question.

If i have both GTK and Qt installed and i run cinfigure with “–with-gtj” or just omit thus iption, i want my program to use GTK and not Qt.

Qt should be used inly when explicitly swt “–with-qt”.

Im already using it in my Makefile, but i need a confugure check.

Thank you.

You wanted something which can tell you if gtk is installed and pkg-config does that job. (i.e. pkg-config --exists gtk4)

You might consider switch to some sort of sane build system that does all this configure work for you, though.

1 Like

GTK defers its discovery and dependency management to pkg-config.

I’m pretty positive @jensgeorg understood you. Autotools does not do anything magical: it just calls commands using the shell, which means your configure.ac file will end up either using shell commands, or m4 macros that wrap shell commands. Regardless, you’ll have to look into the pkg-config documentation.

The Autotools Mythbusters documentation has a whole chapter on pkg-config, with a section specifically on its macros: 3. The PKG_CHECK_MODULES Macro

Ah yes, since you said Makefile I assumed that you hand-write configure and Makefile and did not assume autotools.

@jensgeorg

Ah yes, since you said Makefile I assumed that you hand-write configure and Makefile and did not assume autotools.

Not really.
I manually added pkg-config --cflags gtk+3.0 in the Makefille.am. What I’d like to do is to check GTK presense in configure and then use the above in the Makefile.am. No more unconditional hardcoding…

And I did not write them myself - I used Anjuta to make the Autotools files. Unfortunately Anjuta project died and I have to make/update everything by hand right now.

Thank you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.