GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Aug 28, 2016 8:37 am

All times are UTC

Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Help: Cannot compile even the simplest gtk c program...
PostPosted: Tue Jul 03, 2012 6:27 am 

Joined: Tue Jul 03, 2012 6:02 am
Posts: 1
I am a newbie to gtk, trying to run a sample program I found on

I got a tonload of errors, initial part is I give below:
See the attachment for details.

gtk2 is installed.
Thanks advance

In file included from /usr/include/gio/giotypes.h:30:0,
                 from /usr/include/gio/gio.h:28,
                 from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
                 from /usr/include/gtk-2.0/gdk/gdk.h:32,
                 from /usr/include/gtk-2.0/gtk/gtk.h:32,
                 from simple.c:1:
/usr/include/gio/gioenums.h:651:26: error: ‘GLIB_SYSDEF_AF_INET’ undeclared here (not in a function)
/usr/include/gio/gioenums.h:652:26: error: ‘GLIB_SYSDEF_AF_INET6’ undeclared here (not in a function)
/usr/include/gio/gioenums.h:697:22: error: ‘GLIB_SYSDEF_MSG_OOB’ undeclared here (not in a function)
/usr/include/gio/gioenums.h:698:23: error: ‘GLIB_SYSDEF_MSG_PEEK’ undeclared here (not in a function)
/usr/include/gio/gioenums.h:699:28: error: ‘GLIB_SYSDEF_MSG_DONTROUTE’ undeclared here (not in a function)
In file included from /usr/include/gio/gio.h:28:0,
                 from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
                 from /usr/include/gtk-2.0/gdk/gdk.h:32,
                 from /usr/include/gtk-2.0/gtk/gtk.h:32,
                 from simple.c:1:
/usr/include/gio/giotypes.h:258:48: error: expected ‘)’ before ‘current_num_bytes’


The program is given below:

#include <gtk/gtk.h>

  file taken from
  gcc -o simple simple.c `pkg-config --libs --cflags gtk+-2.0`

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

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);


  return 0;

File comment: sample program and errors I got after compilation
gtk-sample.tar.gz [38.01 KiB]
Downloaded 137 times

Last edited by kakd on Sat Jul 07, 2012 8:29 am, edited 1 time in total.
 Post subject: Re: Help: Cannot compile even the simplest gtk c program...
PostPosted: Wed Jul 04, 2012 6:23 am 

Joined: Fri Jun 22, 2012 5:49 pm
Posts: 3
When I want to compile gtk stuff on Ubuntu I install the gtk development libraries by doing:
sudo apt-get install libgtk2.0-dev

Is that what you did or did you install the packages another way?


 Post subject: Re: Help: Cannot compile even the simplest gtk c program...
PostPosted: Wed Jul 04, 2012 3:11 pm 
GTK+ Geek

Joined: Sat Sep 03, 2011 6:36 pm
Posts: 94
Since you are a newbie, i would recommend using the Anjuta IDE which you can found at the software center.You can also follow this tutorial from the gnome dev center.The program will tell you if a library is missing when you compile and build your program.

Make sure you have installed the depended libraries from synaptic package manager.

 Post subject: Re: Help: Cannot compile even the simplest gtk c program...
PostPosted: Thu Jul 05, 2012 12:58 am 
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 181
Location: USA
I would suggest:

1) Install Ubuntu Precise instead if possible. This will give you gtk 3.4.1. which is close to the newest stable version (3.4.2.)
Either: Search it in Software Center. OR search for and install "Synaptic Package Manager" then install gtk from there (see instructions below)
2) If for some reason you can't change your Ubuntu version (slow computer ect.) Install gtk+-3.0.8 using Synaptic Package Manager. I suggest logging in to "Ubuntu Classic (no effects)" especially for older computers.

You'll learn far more by not using an IDE like Anjuta when your starting out. Compiling from the command line will teach you vital skills and eliminate errors that may arise from the IDE.

To install GTK using Synaptic Package Manager:
1) System->Administration->Synaptic Package Manager
2) Enter your password and click "OK"
3) The left-most column is the package categories, make sure your on "ALL"
4) In the top middle of the screen, under the words: "Quick Filter" type this in the box: libgtk-3-dev
5) The list of search results is displayed.
6) Right or left click on on the box next to libgtk-3-dev and choose: "Mark for installation"
7) A box will open that says: "Mark for additional required changes?"
(There will be three additional things listed in the box: libgtk-3-0, libgtk-3-bin, libgtk-3-common)
8) Choose "Mark"
9) Repeat the process for libgtk-3-doc (the gtk documentation)
10) Repeat the process for devhelp (I can't remember if this is installed by default) Make sure you install "devhelp-common"

Devhelp will be installed under: Applications->Programming.
If Devhelp isn't visible:
1) Right click over the word "Applications" and choose "Edit Menus".
2) Expand the category called "Applications"
3) Click on "Programming"
4) Click on the "Show" box next to Devhelp.

Setup Gedit for you code editor:
1) Go to: Applications->Accessories->Text Editor. (The editor is called Gedit.)
2) In Gedit go to: Edit->Preferences
3) Click on the tab called "Plugins"
4) Choose "Devhelp support"
5) Click the button "Configure Plugin"
6) Save your file as yourprogramname.c This will enable c code highlighting. Then enter your gtk code.
7) When you want documentation about something, say a button (GtkButton) highlight the word "GtkButton" then press the "F2" key.
8) The documentation will open and take you directly to the info about GtkButton.
9) In devhelp go to: Edit->Preferences->Book Shelf
10) Check the books you want. For instance maybe you don't want: "Gtk+ 2 Reference Manual" now that your using gtk3.

Compile and run you GTK programs using the command line:
1) Press "CTRL+ALT+T" to launch the terminal.
If the terminal doesn't launch or if you want to change the short cut keys to launch it go to: System->Preferences->Keyboard Shortcuts
2) Type: cd directoryofyourcode
For example, my code is in: home/zerohour/gtk/programming. Then it's broken down into various folder such as "GtkButton"; "GtkCalendar" ect. So to change directories to the folder "GtkButton" I would enter:
cd gtk/programming/GtkButton

You can get the location of your code file by going to:
1) Places->Home Folder
2) Navigate to your gtk program.
3) Right click on the file and go to "properities"
4) Copy the Location.
5) In the terminal type "cd" then paste the location using: CTRL+SHIFT+v and press enter.

To go up a directory type the following with a space in between the "d" and the "."
cd ..
To retype something that you previously typed press the up and down arrow keys.
To clear the screen type: clear
To list all files and folders in a directory type: ls

I highly recommend looking at command line tutorials for at least the basic commands:
cd, ls, cp, mv, cat, mkdir, sudo, chmod

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group