LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GTK Programming - gtk disappears? (https://www.linuxquestions.org/questions/programming-9/gtk-programming-gtk-disappears-907048/)

rachel_s 10-07-2011 11:52 PM

GTK Programming - gtk disappears?
 
Hello,

I am a beginning programmer, trying to learn C and GTK. I started a tutorial and made it through the first two lessons, then on the third received a curious error:

Code:

fatal error: gtk/gtk.h: No such file or directory compilation terminated.
This is strange because the gtk/gtk.h pre-processor directive was clearly available for the first two programs; they compiled and ran just fine.

Thanks for any help with this. :)

Doc CPU 10-08-2011 06:43 AM

Hi there,

Quote:

Originally Posted by rachel_s (Post 4492877)
Code:

fatal error: gtk/gtk.h: No such file or directory compilation terminated.
This is strange because the gtk/gtk.h pre-processor directive was clearly available for the first two programs; they compiled and ran just fine.

have a look at the C/C++ source files, especially the #include directive referencing the gtk.h header file. Is the header file name enclosed in quotation marks or brackets?
#include "gtk/gtk.h" starts searching from the directory that contains the C source file
#include <gtk/gtk.h> starts searching from the compiler's default or configured include directory

Right now, that's all I can think of as a reason.

[X] Doc CPU

theNbomr 10-08-2011 01:09 PM

Also, compare the compiler commandline arguments. If you are using make to build the program, the arguments may be embedded in the Makefile. Look especially for the '-I' (uppercase 'eye') argument, possibly embedded in something like ${CFLAGS}.

--- rod.

rachel_s 10-09-2011 01:25 AM

Quote:

Originally Posted by Doc CPU (Post 4493051)
Hi there,



have a look at the C/C++ source files, especially the #include directive referencing the gtk.h header file. Is the header file name enclosed in quotation marks or brackets?
#include "gtk/gtk.h" starts searching from the directory that contains the C source file
#include <gtk/gtk.h> starts searching from the compiler's default or configured include directory

Right now, that's all I can think of as a reason.

[X] Doc CPU

I'm using the correct delimiters:

Code:

#include <gtk/gtk.h>
Quote:

Originally Posted by theNbomr (Post 4493255)
Also, compare the compiler commandline arguments. If you are using make to build the program, the arguments may be embedded in the Makefile. Look especially for the '-I' (uppercase 'eye') argument, possibly embedded in something like ${CFLAGS}.

--- rod.

I'm using

Code:

gcc codename.c -o programname
So I think I'm safe in this regard.

Thanks to both of you for your help. This problem seems quite perplexing; I hope I don't have to backup and do a re-install. :(

I at least wish I knew what I did to make the headers "disappear" so I don't pull that one again.

Nylex 10-09-2011 01:34 AM

Quote:

Originally Posted by rachel_s (Post 4493594)
Code:

gcc codename.c -o programname

You're not telling gcc where to find the headers, or to link the relevant libraries. The tutorial tells you how to specify the correct flags; you use pkg-config: http://developer.gnome.org/gtk-tutor...able/x111.html.

theNbomr 10-09-2011 11:01 AM

If the aforementioned tutorial is online, please post a link to it. If you are too new here to post links, send me a private LQ message with the link, and I'll post it if it works.
--- rod.

ta0kira 10-09-2011 11:11 PM

For GTK+ you generally use `pkg-config --cflags gtk+-2.0` in the gcc call, in addition to your own options. Similarly, you'd use `pkg-config --libs gtk+-2.0` to get linker flags. Keep in mind that both provide flags corresponding to the configuration of your GTK+ installation; therefore, code the `...` into your makefile, not the output of the respective commands. So something like this, if you compile and link at the same time:
Code:

gcc `pkg-config --cflags gtk+-2.0` codename.c -o programname `pkg-config --libs gtk+-2.0`
Kevin Barry

rachel_s 10-10-2011 11:06 PM

Quote:

Originally Posted by Nylex (Post 4493597)
You're not telling gcc where to find the headers, or to link the relevant libraries. The tutorial tells you how to specify the correct flags; you use pkg-config: http://developer.gnome.org/gtk-tutor...able/x111.html.

Quote:

Originally Posted by ta0kira (Post 4494250)
For GTK+ you generally use `pkg-config --cflags gtk+-2.0` in the gcc call, in addition to your own options. Similarly, you'd use `pkg-config --libs gtk+-2.0` to get linker flags. Keep in mind that both provide flags corresponding to the configuration of your GTK+ installation; therefore, code the `...` into your makefile, not the output of the respective commands. So something like this, if you compile and link at the same time:
Code:

gcc `pkg-config --cflags gtk+-2.0` codename.c -o programname `pkg-config --libs gtk+-2.0`
Kevin Barry

Nylex and ta0kira: Thank you, this was it! Bit embarrassed...

Nylex 10-11-2011 12:41 AM

No problem. I did think it was slightly strange, though, as you said you'd been able to build other GTK+ programs without any trouble.


All times are GMT -5. The time now is 04:53 PM.