GTK+ program won't compile

Discussions Regarding Software

Moderator: Moderators

GTK+ program won't compile

Postby davbeck » Sat Jul 14, 2007 23:45

Hey I am trying to learn GTK+ but I can't compile any programs (hello world being the first tried).

I am new to programming in general and especially to graphical programming, so expect newb answers (I am so sorry for my newbness)

basically the libraries aren't loaded. but /usr/bin/gtk-demo works perfectly and I couldn't find any packages with emerge that hadn't been installed.

here is the hello world code (from foundations in GTK+)

Code: Select all
#include <gtk/gtk.h>

int main (int argc,
          char *argv[])
{
  GtkWidget *window;

  /* Initialize GTK+ and all of its supporting libraries. */
  gtk_init (&argc, &argv);

  /* Create a new window, give it a title and display it to the user. */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Hello World");
  gtk_widget_show (window);

  /* Hand control over to the main loop. */
  gtk_main ();
  return 0;
}


and when I compile it

Code: Select all
$ gcc -Wall -g helloworld.c `pkg-config --cflags gtk+-2.0` \`pkg-config --libs gtk+-2.0
gcc: `pkg-config: No such file or directory
gcc: gtk+-2.0: No such file or directory
cc1: error: unrecognized command line option "-flibs"
I love this distro!!!
User avatar
davbeck
Simple Hen
 
Posts: 63
Joined: Sun Apr 01, 2007 16:26
Location: Reno NV

Postby dave_p_b » Sun Jul 15, 2007 2:02

Hi

Try to compile like this gcc helloworld.c -o helloworld `pkg-config --cflags --libs gtk+-2.0`
Just copy and paste this so you get those funny quote things in the right place.
If you want to find the page I got this from then check here http://www.gtk.org/tutorial/c39.html

Infact, just search gtk "hello world" in Google and there are lots of examples of what you are looking for.

I understand what you are going through, I'm learning Python at the moment. :? luckily there's no compiling that goes on in Python as of yet. Python's a good one to learn as it is used in superkaramba themes too.

Good luck and all the best in learning gtk

Dave

p.s. Also, what you should have had in yours was:
gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
and what you had was:
gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` \ `pkg-config --libs gtk+-2.0

Firstly, you mist out the end ` mark and you didn't need the \ (backslash) in there. A \ (backslash) should only appear at the end of a line if nothing else follows it apart from on the second line. like this:
gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` \
`pkg-config --libs gtk+-2.0`
User avatar
dave_p_b
Old Dear Hen
 
Posts: 607
Joined: Fri Dec 15, 2006 1:39
Location: Exeter, UK

Postby davbeck » Sun Jul 15, 2007 2:49

thanks, it works great when you type the command correctly!!!

I found that alternative method as well a few minutes ago, apparently this book seems to be the only source to use the original method for a new programmer.
I love this distro!!!
User avatar
davbeck
Simple Hen
 
Posts: 63
Joined: Sun Apr 01, 2007 16:26
Location: Reno NV


Return to Software in General

Who is online

Users browsing this forum: No registered users and 1 guest