0

I am somewhat new to both Linux and C programming. My goal is to set up an environment to program GTK+ GUIs. I am programming on Linux Mint using CLion. I am able to locate the GTK (2 and 3 header) files in the expected place. According to the internet, everything is in order wrt the return value of pkg-config --cflags gtk+-2.0

However, I cannot find the object or .c files for GTK. Everything is compiling but I am getting linking errors, which is what made me look for the files in the first place.

My question is- does Debian and its derivatives come with GTK already installed and are those binaries accessible for programmers such as myself writing new applications ? Are we supposed to use them and not install GTK? Or do I have to install GTK from the GTK site and use those ?

Is there some reason I only have .h files? Is it normal? Or is my machine in an aberrant state?

  • Debian and derivatives come with Gtk installed, or you could also install Gtk devel packages using Synaptic if needed. Typically, installing Gtk from the Gtk website is a huge undertaking, sometimes impossible because of dependency conflicts. – theGtknerd Dec 09 '18 at 21:56
  • I have to ask the question- where are the libraries? because I have to tell CMakeLists about them . The meta-question here is: where can I find the relationship between Linux's libraries' various locations and GTK build-time requirements laid out so I can understand them (and things like them to come)? –  Dec 09 '18 at 22:55
  • Ok, I have to admit I am a Python guy. However, when I need to find the location of files on Linux, I use Synaptic's Properties>Installed files. In this case, package libgtk-3-dev has a whole bunch of stuff installed to usr/include/gtk-3.0. Hope this helps. – theGtknerd Dec 10 '18 at 00:25
  • Thank you it does help! –  Dec 10 '18 at 11:18

2 Answers2

3

You just need the headers and the runtime. The C files would be necessary only if you wanted to rebuild GTK+ yourself, but your distro provides packages to make it (a lot) easier. You already have the GTK+ 3 headers, so the development package for GTK+ 3 is installed. If it wasn't, you'd need to install it using:

sudo apt-get install libgtk-3-dev

Everything else you want to know, like how to compile your application is in the GTK+ documentation, in the Getting Started with GTK+ section.

As for using CMake with GTK+, I have an old example that should still work with recent CMake versions. It could be better written in modern CMake though. However the GTK+ team and the GNOME project switched to the Meson build system, which I would recommend if you don't care about the CLion integration.

A Meson project file for a simple GTK+ program would be (example from their website):

project('tutorial', 'c')
gtkdep = dependency('gtk+-3.0')
executable('demo', 'main.c', dependencies : gtkdep)

More at http://mesonbuild.com/Tutorial.html#adding-dependencies

liberforce
  • 11,189
  • 37
  • 48
2

Gtk is pretty much present in all linux distribution's and to program in it you need the development library.

sudo apt-get install libgtk-3-dev

To compile the application use

pkg-config --libs --cflags gtk+-3.0

https://linux.die.net/man/1/pkg-config

Siva Guru
  • 694
  • 4
  • 12
  • 1
    Please please please, 2019 is coming and GTK+ 3 has been released 8 years ago. Nobody should use GTK+ 2 except for maintaining old projects not worth migrating. – liberforce Dec 18 '18 at 09:44