Jump to content

[C] Error compiling GTK program [solved]


Recommended Posts

Hi there,

 

After a long trip to install all necessary package for programming, I have tried a small script to test gtk application in C:

 

/* filename: gtkdemo.c */
#include <stdio.h>
#include <gtk/gtk.h>

int main(int argc, char* argv[])
{
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);
gtk_main();

return 0;

}

 

and then I compile and get errors:

> pete cmd: gcc gtkdemo.c -o gtkdemo 'pkg-config --cflags --libs gtk+-2.0'
gcc: pkg-config --cflags --libs gtk+-2.0: No such file or directory
gtkdemo.c:2:21: error: gtk/gtk.h: No such file or directory
gtkdemo.c: In function ‘main’:
gtkdemo.c:6: error: ‘GtkWidget’ undeclared (first use in this function)
gtkdemo.c:6: error: (Each undeclared identifier is reported only once
gtkdemo.c:6: error: for each function it appears in.)
gtkdemo.c:6: error: ‘window’ undeclared (first use in this function)
gtkdemo.c:8: error: ‘GTK_WINDOW_TOPLEVEL’ undeclared (first use in this function)

 

I search on Google, and all of them said because of environment variable PKG_CONFIG_PATH is not set to folder containing *.pc

Afterward, I set my PKG_CONFIG_PATH variable:

> pete cmd: export PKG_CONFIG_PATH=/usr/lib/pkgconfig
> pete cmd: echo $PKG_CONFIG_PATH
/usr/lib/pkgconfig

 

I re-compile my source gtkdemo.c above again, BUT STILL THOSE ERRORS ????

Could any1 help me w/ this problem?

 

p/s: WHY MANDRIVA MAKES IT SO HARD TO DEVELOP/PROGRAM??? [Redhat/Fedora/openSUSE/Slax/Ubuntu/openBSD...I've been used and much easier than MANDRIVA]

Link to comment
Share on other sites

...and then I compile and get errors:

> pete cmd: gcc gtkdemo.c -o gtkdemo 'pkg-config --cflags --libs gtk+-2.0'
gcc: pkg-config --cflags --libs gtk+-2.0: No such file or directory

Any idea why you're using "pkg-config" (something to do with packaging??) instead of the recommended "gtk-config" (something to do with gtk) ?

 

p/s: WHY MANDRIVA MAKES IT SO HARD TO DEVELOP/PROGRAM??? [Redhat/Fedora/openSUSE/Slax/Ubuntu/openBSD...I've been used and much easier than MANDRIVA]
Please feel free to retract this if the problem is in fact just a typo on the compile command ;)

 

Edit: OK, my bad, you're right, it should be pkg. This changed apparently since gtk1. pkg-config is right. But I think it's a problem with your apostrophe - it should be a backtick. Try the command

pkg-config --cflags gtk+-2.0

and see if that works. If it does, retry your gcc command but make sure you use a backtick ` instead of an apostrophe '.

Edited by neddie
Link to comment
Share on other sites

In Mandriva, it's equally hard to compile stuff as in Debian, Ubuntu, Fedora/RedHat, OpenSuSE and many other distros that are following the package policy of spilt packages. You don't have good chances to compile anything at all, unless you take care to install a big bunch of -devel packages before.

On the other hand, you have Slackware/Slax, Gentoo, Archlinux plus a few more which are following the monolithic package model, and so when installing a package the -devel binaries get installed as well. This means both good and bad things: the good ones are that you will never have to care about installing such packages when you need to build something from source, and the bad ones are that you will keep on harddisk files worth several hundred megabytes in weight, without (probably) ever using a single one of them. Personally, I prefer monolithic packages, but I could also live with the other category as well.

Link to comment
Share on other sites

@lanw1974: if I miss any development files, the error should be different.

 

@neddle: well, it's awesome recognition from apostrope and back tick. It solved the problem. But I still wonder why gcc use back tick o.@;;

 

@scarecrow: I'm the big fan of Fedora and Redhat family. I always compile and install package manually; rarely use package manager. Slax is my favorite one of monolithic and disk space is not problem (well, honestly price is much cheaper nowadays)

 

Thanks u guys for solution and suggestion :)

[Problem Solved]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...