Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: paspas on November 01, 2006, 02:00:31 am

Title: how to add libraries for gtk in linux?
Post by: paspas on November 01, 2006, 02:00:31 am
Hi, i'm sorry about my english :)


I'm trying to compile a simple .c program to use GTK+ libraries

#include <gtk/gtk.h>
........

when i compile the program says :

error : gtk/gtk.h  doesn't exist.

using anjuta it runs. May be i haven't configurate code:blocks, where and what i must change?

Thank you very much
Title: Re: how to add libraries for gtk in linux?
Post by: stahta01 on November 01, 2006, 02:15:15 am
You need to set the compiler include directories.

Try "Project" -> "Build Options" -> "Directories" -> "Compiler"
Add the path to the folder gtk that contains the file gtk.h

Edit: Fixed example below cut and paste error.

If the full path to the file gtk.h is /usr/local/include/gtk/gtk.h
then add the path /usr/local/include

Edit: You may need to update "Project" -> "Build Options" -> "Directories" -> "Linker" it should be the path to the GTK+ Libraries but I have no idea what that is. I always wait till I get the error on linking before adding "Linker" directories.

Tim S

If you still get errors try turning on Full Compile Logging to see the command set to GCC etc.
//-- Full Compile Logging --
   Settings->Compiler and Debugger->"Other"->Compiler logging = "Full command line".

PS: I am a window user so I might make some Linux error in my advice.
Title: Re: how to add libraries for gtk in linux?
Post by: paspas on November 01, 2006, 12:28:55 pm
after i added in project/ build options/ Directories/ compiler this :

/usr/include/pango-1.0/
/usr/include/gtk-2.0
/usr/include/glib-2.0
/usr/lib/glib-2.0/include/
/usr/include/cairo/
/usr/lib/gtk-2.0/include/
/usr/include/atk-1.0/

i can compile but at the end i found this error:

-------------- Build: Release in holagtk3 ---------------
Linking console executable: bin/Release/holagtk3
obj/Release/holagtk.o: In function `main':
holagtk.c:(.text+0x1c): referencia a `gtk_init' sin definir (reference to ... whithout define)
holagtk.c:(.text+0x28): referencia a `gtk_window_new' sin definir
holagtk.c:(.text+0x30): referencia a `gtk_widget_show' sin definir
holagtk.c:(.text+0x35): referencia a `gtk_main' sin definir
collect2: ld returned 1 exit status

Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
 
the program is this:

/* principio del ejemplo base */

#include <gtk/gtk.h>

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

    gtk_init (&argc, &argv);

    ventana = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_show (ventana);

    gtk_main ();

    return 0;
}
/* final del ejemplo */


could you help me?


THANK YOU!

Title: Re: how to add libraries for gtk in linux?
Post by: stahta01 on November 01, 2006, 04:15:32 pm
Please turn Full Compile Logging using
   Settings->Compiler and Debugger->"Other"->Compiler logging = "Full command line".

The output will help finding cause of the error you are getting.

Since this is a link error the linker values in codeblocks needs verified.
What is in "Project" -> "Build Options" -> "Directories" -> "Linker"
What is in "Project" -> "Build Options" -> "Linker" -> "Link Libraries"

GTK+ Libraries that may be needed under "Link Libraries"
 GLib
 Pango
 ATK
From URL http://www.gtk.org/

Note: The above way is the window user way.

See http://www.gtk.org/tutorial/x111.html for the Linux way.

I have modified info from tutorial/x111.html for codeblocks use below:

Under "Project" -> "Build Options" -> "Compiler" -> "Other Options" try adding `pkg-config --cflags gtk+-2.0`
Note: The tick marks are needed and it must be that tick mark.

Under "Project" -> "Build Options" -> "Linker" -> "Other linker options" try adding 
`pkg-config --libs gtk+-2.0`

Note: The tick marks are needed and it must be that tick mark.

Tim S
 

Title: Re: how to add libraries for gtk in linux?
Post by: paspas on November 01, 2006, 08:17:45 pm
EUREKA!!!!

adding in Project / Build options / linker/ other options

`pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`


WORKS !

thank you very much