I am trying to use make command to build. I am following this. I am compiling a code using GTK+2 and C language
hp@ubuntu:~/amhello$ make
make all-recursive
make[1]: Entering directory `/home/hp/amhello'
Making all in src
make[2]: Entering directory `/home/hp/amhello/src'
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
main.c:3:20: fatal error: gtk/gtk.h: No such file or directory
compilation terminated.
make[2]: *** [main.o] Error 1
make[2]: Leaving directory `/home/hp/amhello/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/hp/amhello'
make: *** [all] Error 2
this is the main.c code
#include<config.h>
#include<stdio.h>
#include<gtk/gtk.h>
void static call(GtkWidget *widget,gpointer data) {
g_print("%s \n",(gchar*) data);
}
int main(int agrc, char *agrv[]) {
gtk_init(&agrc,&agrv);
GtkWidget *window,*button;
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window,"delete-event",G_CALLBACK(gtk_main_quit),NULL);
gtk_window_set_title(GTK_WINDOW(window),"one button");
button=gtk_button_new_with_label("hello world");
g_signal_connect(button,"clicked",G_CALLBACK(call),(gpointer) "hello world");
gtk_container_set_border_width(GTK_CONTAINER(window),10);
gtk_container_add(GTK_CONTAINER(window),button);
gtk_widget_show_all(window);
gtk_main();
return (0);
}
This means that you don't have the gtk headers to build stuff using GTK+. Is really weird that the error didn't showed up at ./configure step. To solve this just do:
or
libgtk-3-dev
.That should do it.
That is also needed so that you can do cool things like:
It allows you to use
pkg-config
to save a whole lot of timeGtk3 equivalent debian/ubuntu package is
libgtk-3-dev
Since you are using autotools to generate your Makefiles, you need to tell automake how to find the header and library dependencies of your project and incorporate them into the final Makefiles. This is not my area of expertise but I will try to point you in the right direction. Most of the following is based on the tutorial found at Using C/C++ libraries with Automake and Autoconf
First, you must modify the top level configure.ac file to add the Gtk-2.0 dependency. You can use the
PKG_CHECK_MODULES
macro to runpkg-config
to find the corresponding include and library directives - it's good practice to check thatpkg-config
exists first, so we should add aPKG_PROG_PKG_CONFIG
test as well. The bolded portions indicate what`s added, relative to the files in the original amhello tutorial that you started from.Then in your
src/Makefile.am
you can retrieve the CFLAGS and LIBS using theGTK
identifier that you used in thePKG_CHECK_MODULES
macro aboveWhen you re-run
make
, it should re-generate your src/Makefile with the appropriate-I
include paths,-L
library paths and libraries.In CentOS 7: a) packages:
b) editing header section of your snippet:
to
c) compiling using:
or
and
d) executing using:
worked for me!