User avatar
SpazzTechTom
Posts: 15
Joined: Sat Jan 31, 2015 12:50 am
Location: Glen Rock, PA. USA
Contact: Website

Can't link to GTK libraries

Wed Aug 12, 2015 3:08 am

Hello everyone,

I had what seemed like a strange issue with gcc not being able to find the gtk libraries, but solved it. I thought I would share what I found.

I had gtk.h installed at /usr/include/gtk-3.0/gtk/. I definitely had dev version.

In my program i had:
#include <gtk-3.0/gtk/gtk.h>

In my build settings in Geany I included -lgdk-3.0.

When I tried to compile or build I get the following error:
/usr/include/gtk-3.0/gtk/gtk.h:30:21: fatal error: gdk/gdk.h: No such file or directory

I had a folder called gdk inside the gtk-3.0 folder and it contains gdk.h, but the gtk.h was using:
#include <gdk/gdk.h>

It seemed that having the gtk-3.0 folder in the path was what the problem was. I moved both the gtk and gdk folder into the /usr/include/ folder directly, and now its happy. (I also removed gtk-3.0 from the #include line) I suppose I could also re-write all the headers to include the gtk-3.0 folder in the path, but this seemed to work for now.

Maybe there is a better way to set this up. Any further recommendations out there?
SpazzTechTom
Having fun with technology!

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Can't link to GTK libraries

Wed Aug 12, 2015 7:03 am

I left everything where it was installed and used `pkg-config --cflags gtk+-3.0` and `pkg-config --libs gtk+-3.0 gmodule-2.0` in the Makefile.

Perhaps see what pkg-config is doing differently to your set up.

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Can't link to GTK libraries

Wed Aug 12, 2015 7:06 am

Hi,

I suppose these directories were placed at their respective locations by the install process. Moving them around is - in that case - perhaps not the best of ideas, because with the next upgrade thing might get mixed up (not sure about this tho).

Anyway, why not prevent this and just create symbolic links?

My $0.02...
Gerard
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: Can't link to GTK libraries

Wed Aug 12, 2015 9:10 am

SpazzTechTom wrote:. I moved both the gtk and gdk folder into the /usr/include/ folder directly, and now its happy.
Now you have two problems.
1) Your Geany configuration is wrong.
2) gtk.h is in the wrong place.

You are just lucky that the two problems are cancelling out each other.

You should put the header file back where it should be and (as previously suggested) use pkg-config to get the correct compile and link flags into your Geany configuration.

I don't have gtk3 development files on this box (which is a Mint X86-64 box, but the principles will still apply) , but gtk2 development is installed....

Code: Select all

pkg-config --cflags --libs gtk+-2.0
-pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/harfbuzz  -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lgobject-2.0 -lglib-2.0 -lfreetype 
Note "-I/usr/include/gtk-2.0" will mean that "#include <gtk/gtk.h>" will find /usr/include/gtk-2.0/gtk/gtk.h
The same will apply for gtk-3.0.

Currently you won't be able to build any correctly configured gtk-3.0 code.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: Can't link to GTK libraries

Wed Aug 12, 2015 9:11 am

GerardWassink wrote: Anyway, why not prevent this and just create symbolic links?
Another BAD IDEA. Get the build config right, don't fudge it with symlinks.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: Can't link to GTK libraries

Wed Aug 12, 2015 10:51 am

PeterO wrote:
GerardWassink wrote: Anyway, why not prevent this and just create symbolic links?
Another BAD IDEA. Get the build config right, don't fudge it with symlinks.

PeterO
Okay dude, just trying to help. No need to bash!
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: Can't link to GTK libraries

Wed Aug 12, 2015 10:59 am

GerardWassink wrote: Okay dude, just trying to help. No need to bash!
:lol:

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

profro
Posts: 45
Joined: Tue Nov 15, 2016 1:26 pm

Re: Can't link to GTK libraries

Wed Nov 30, 2016 4:24 pm

I am still having issues with this after adding the following to my makefile

Code: Select all

LIBS = -lwiringPi `pkg-config --libs --cflags gtk+-3.0` -I/usr/include/gtk-3.0
it still errors out with the following:
/usr/include/gtk-3.0/gtk/gtk.h:30:21: fatal error: gdk/gdk.h: No such file or directory

#include <gdk/gdk.h>
It appears that the gtk.h #include <gdk/gdk.h. I have confirmed that the gdk.h file is there. What gives?

profro
Posts: 45
Joined: Tue Nov 15, 2016 1:26 pm

Re: Can't link to GTK libraries

Thu Dec 01, 2016 6:39 pm

I solved this by adding the following to makefile

Code: Select all

LIBS = -lwiringPi `pkg-config --libs gtk+-3.0`

CFLAGS = `pkg-config --cflags gtk+-3.0`

Return to “Graphics programming”