Compiling GLib Applications
https://developer.gnome.org/glib/stable/glib-compiling.html
Here's a tutorial, a little old but still applicable: http://www.ibm.com/developerworks/linux/tutorials/l-glib/
Here's a tutorial on the GObject part of GLib: http://www.arbingersys.com/2009/07/missing-gobject-tutorial-sample.html
Also check out the excellent book 'Foundations of GTK Development' by Andrew Krause, it has a chapter on GLib: http://www.gtkbook.com/
---------------------------------------------------------------------------------------------------------------
Glib compiler出現 test.c:2:18: fatal error: glib.h: No such file or directory
安裝下面package可以解決
$sudo apt-get install libglib2.0-dev
----------------------------------------------------------------------------------------------------------------
Glib Helloworld example code
#include <stdio.h> #include <glib.h> int main(int argc, char** argv) { GList* list = NULL; list = g_list_append(list, "Hello world!"); char* str = g_list_first(list)->data; printf("The first item is '%s'\n", str); return 0; }
output:The first item is 'Hello world!'
How to compile
$gcc test.c -Wall -o test `pkg-config --cflags --libs glib-2.0`