gtk/gtk.h problem

Hi, I am am trying to learn gtk programing. I use Ubuntu 10.10, and that is what I want to compile(the first gtk tutorial):

#include <gtk/gtk.h>
int main(int argc, char *argc[])
{
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_main ();
return 0;
}


The problem is that bough g++ and gcc can't find "gtk/gtk.h":
"gtk.cpp:1: fatal error: gtk/gtk.h: No such file or directory
compilation terminated."

I have already installed libgtk2.0-dev and it doesn't help. How can I solve that issue? Thank you!
You're missing some include paths.
Add the following to the compiling call: `pkg-config gtk+-2.0 --cflags`
And the following to the linking call: `pkg-config gtk+-2.0 --libs`

Note that there is gtkmm, which is probably a better choice if you're using C++.
What will be the correct syntax of the command? I used to be windows user and steel can't get comfortable enough with those compilers.
Example:
g++ main.cpp -Os -s `pkg-config gtk+-2.0 --cflags` `pkg-config gtk+-2.0 --libs`


Note that your second parameter in main has the same name as the first one. The second one is normally called argv.
Last edited on
Fixed the syntax error, and tried to compile:
g++ gtk.cpp -Os -s `pkg-config gtk+-2.0 --cflags` `pkg-config gtk+-2.0 --libs`
And this is what I get:
1
2
3
4
5
6
7
8
gtk.cpp: In function ‘int main(int, char**)’:
gtk.cpp:5: error: ‘GtkWidget’ was not declared in this scope
gtk.cpp:5: error: ‘window’ was not declared in this scope
gtk.cpp:7: error: ‘gtk_init’ was not declared in this scope
gtk.cpp:9: error: ‘GTK_WINDOW_TOPLEVEL’ was not declared in this scope
gtk.cpp:9: error: ‘gtk_window_new’ was not declared in this scope
gtk.cpp:10: error: ‘gtk_widget_show’ was not declared in this scope
gtk.cpp:12: error: ‘gtk_main’ was not declared in this scope 


Solved it. Thanks for the help!
Last edited on
Strange, this compiles fine for me on Ubuntu 10.10.
I assume you're missing another package. You can try installing libgtkmm-2.4-dev. Perhaps it will cause the missing dependency to be installed, whatever it might be.
Topic archived. No new replies allowed.