I. Brief Introduction and Configuration
GLib is a cross-platform library written in C language. It was initially part of GTK +, but in the second version of GTK +, developers decided to separate code unrelated to the graphic interface, the code is then assembled into GLib. Because GLib has the cross-platform feature, programs written with it can be compiled and run on other programs without significant modifications.
The glib library is the most common C language function library in Linux. It has good portability and practicability.
Glib is the basis of Gtk + Library and Gnome. Glib can be used on multiple platforms, such as Linux, Unix, and Windows. Glib provides substitutes for many standard and common C language structures.
All contents of the good AI Park blog is original, if reproduced please indicate the source http://blog.csdn.net/myhaspl/
If the function in the glib library is to be used in the program, it should contain the glib. h header file (the gtk. h and gnome. h header files already contain glib. h)
1. Install glib in Freebsd
Cd/usr/ports/devel/glib20
Portsnap fetch extract
Looking up portsnap.FreeBSD.org mirrors... 7 mirrors found.
Fetching snapshot tag from isc.portsnap.freebsd.org... done.
Fetching snapshot metadata... done.
Updating from Fri Dec 6 11:20:31 CST 2013 to Mon Dec 23 21:23:19 CST 2013.
Fetching 4 metadata patches... done.
Applying metadata patches... done.
Fetching 4 metadata files... gunzip: (stdin): unexpected end of file
Metadata is upt.
Root @ dp:/usr/ports/devel/glib20 # ls
Makefile distinfo files pkg-descr pkg-plist
Root @ dp:/usr/ports/devel/glib20 # make install clean
==> License LGPL20 accepted by the user
==>Found saved configuration for glib-2.36.3
==> Fetching all distfiles required by glib-2.36.3 for building
==> Extracting for glib-2.36.3
=> SHA256 Checksum OK for gnome2/glib-2.36.3.tar.xz.
==> Patching for glib-2.36.3
==> Glib-2.36.3 depends on package: libtool> = 2.4-found
==> Applying FreeBSD patches for glib-2.36.3
..........................
..........................
2. configuration and installation in windows
3. test:
Linux/unix testing, taking freebsd as an Example
First, let's take a look at the program below. In the editor, enter the following program. The program first creates 20 random numbers ranging from 1 to 30000000 and displays them on the screen. Then, it calculates the total number of times, and output the computing time.
# Include
Int main (int argc, char * argv [])
{
GRand * rand;
GTimer * timer;
Gint n;
Gint I, j;
Gint x = 0;
Rand = g_rand_new (); // creates a random number object.
For (n = 0; n <20; n ++)
{// Generate a random number and display it
G_print ("% d \ t", g_rand_int_range (rand, 1,100 ));
}
G_print ("\ n ");
G_rand_free (rand); // release the random number object.
// Create a timer
Timer = g_timer_new ();
G_timer_start (timer); // start timing
For (I = 0; I <10000; I ++)
For (j = 0; j <3000; j ++)
X ++; // accumulative
G_timer_stop (timer); // time end
// Output timing results
G_print ("% ld \ tall: %. 2f seconds was used! \ N ", x, g_timer_elapsed (timer, NULL ));
}
Compile
Dp @ dp :~ /Gliblearn % gcc 'pkg-config -- cflags -- libs glib-2.0 gthread-2.0 'a. c-o mytest
Last run:
Dp @ dp :~ /Gliblearn %./mytest
96 24 52 87 52 16 62 17 78 62 6 33 53 87 3 40 69 20 33
30000000 all: 0.08 seconds was used!
Dp @ dp :~ /Gliblearn %