LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-05-2007, 11:47 AM   #1
abadfish
LQ Newbie
 
Registered: Jul 2007
Location: California, USA
Distribution: Ubuntu
Posts: 5

Rep: Reputation: 0
unable to compile in GTK


I'm new to linux so please bear with me...

I successfully installed GTK 2.10.14 on Ubuntu 7.04. I'm now going through the tutorial on GTK.org. I'm trying to do the first program called base.c. here is the code:

Quote:
#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;
}
I try to compile the program with the following (as per the tutorial):

Quote:
% gcc base.c -o base 'pkg-config --cflags --libs gtk+-2.0'
I get the following error messages:

Quote:
gcc: pkg-config --cflags --libs gtk+-2.0: No such file or directory
base.c:1:21: error: gtk/gtk.h: No such file or directory
base.c: In function ‘main’:
base.c:6: error: ‘GtkWidget’ undeclared (first use in this function)
base.c:6: error: (Each undeclared identifier is reported only once
base.c:6: error: for each function it appears in.)
base.c:6: error: ‘window’ undeclared (first use in this function)
base.c:10: error: ‘GTK_WINDOW_TOPLEVEL’ undeclared (first use in this function)
I'm assuming the problem is in the first line where its looking for pkgconfig. I have pkgconfig stuff in two directories, /usr/local/lib/pkgconfig and /usr/lib/pkgconfig. The pkgconfig in /usr/local/lib contains a folder called gtk+-2.0.

So I've added the following to my env:

Quote:
% export PKG_CONFIG_PATH=/usr/local/lib
I've also tried all of the following:

Quote:
% export PKG_CONFIG_PATH=/usr/local/lib

% export PKG_CONFIG_PATH=/usr/local/lib:/usr/lib

% export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

% export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
None of those have allowed me to compile.


Can anybody shed some light on what I'm doing wrong?????

Thanks in advance.
 
Old 08-05-2007, 11:52 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
When you compile, you need to use backticks (`) around the pkg-config part, rather than normal single quotes ('):

gcc base.c -o base `pkg-config --cflags --libs gtk+-2.0`
 
Old 08-05-2007, 11:52 AM   #3
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
You have to install the development package for Gtk on distros like Ubuntu. They are the ones that are suffixed with -dev or -devel.
 
Old 08-05-2007, 12:07 PM   #4
abadfish
LQ Newbie
 
Registered: Jul 2007
Location: California, USA
Distribution: Ubuntu
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Nylex
When you compile, you need to use backticks (`) around the pkg-config part, rather than normal single quotes ('):

gcc base.c -o base `pkg-config --cflags --libs gtk+-2.0`
Thank you, that did the trick!!! I'm such a

Quote:
Originally Posted by weibullguy
You have to install the development package for Gtk on distros like Ubuntu. They are the ones that are suffixed with -dev or -devel.
I saw those. However, when I selected those for install, it wanted to install a bunch of other packages (e.g. cairo, pango, atk, etc) which 1) I have already installed and 2) were older version than the ones I installed. So I chose not to go that route.

thanks for your replies!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to compile gtk/gnome apps. google01103 SUSE / openSUSE 6 02-14-2008 10:26 AM
gtk-sharp does not compile gecici90 Linux - Software 0 07-18-2006 05:26 PM
GTK Compile Problem MRLindstrom Linux - Software 2 01-24-2005 02:30 AM
Unable to compile from source... can't find GTK kaega2 Mandriva 4 06-01-2004 12:08 PM
GTK 2.2 Compile? Allen614 Slackware 2 01-05-2003 10:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration