7

I am trying to work with gtk which is located at /usr/include/gtk-3.0/gtk/ .., but all of the header files in the toolkit have #include <gtk/gtk.h>.

Aside from adding /usr/local/gtk-3.0 to PATH or adding gtk-3.0 to all the include preprocessors, what other options does one have with this?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
sherrellbc
  • 2,461
  • 7
  • 28
  • 41

2 Answers2

6

Adding the appropriate directory to your include path is exactly what you're supposed to do in this case, only you're supposed to do it by pkg-config. Accessing the files directly using full pathnames is unsupported.

Add something like this to your Makefile:

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

This will automatically add the correct compiler and linker options for the current system.

Celada
  • 43,173
  • 5
  • 96
  • 105
  • The IDE I am currently using uses CMake to generate makefiles and if I use my own I lose the ability to see output in the IDE's console. Do you have a suggestion on how to add this to the compiler arguments using CMake? [This](http://zetcode.com/tutorials/gtktutorial/firstprograms/) website shows that you may compile by adding ``pkg-config --libs --cflags gtk+-3.0``. I tried add_definitions('..'), but for some reason afterwards I get the error that it now cannot find iostream and pthreads, headers that are resident in `/usr/include` directly. – sherrellbc Dec 16 '14 at 21:09
  • Sorry, I don't use CMake but the first Google hit for "CMake pkg-config" suggests [this FindPkgConfig module](http://www.cmake.org/cmake/help/v3.0/module/FindPkgConfig.html) for using `pkg-config` from within CMake. To be honest I don't fully understand how that's supposed to work from the examples but [this other site](http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries) links to that same module so it does kind of look like this "correct" thing to use. I don't know if that helps. – Celada Dec 16 '14 at 21:19
  • Compiling directly from the terminal works fine, I am just having issues getting it all to work using CMake. Thank you for your answer. – sherrellbc Dec 16 '14 at 21:22
4

The PATH environment variable is the search path for executables, not for other kinds of files. For include files, you need to arrange to pass the option -I/usr/include/gtk-3.0/gtk to the compiler. Typically, you do that by setting a variable defined by a makefile (usually CFLAGS='-I/usr/include/gtk-3.0/gtk'), or by passing an argument to ./configure (typically ./configure --includedir=/usr/include/gtk-3.0/gtk).

With Gtk and other software following Freedesktop practices, the proper way to indicate the location of include files, as well as other compiler and linker options, is with pkg-config, as described in Celada's answer.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175