我有很多知識都是通過閱讀別人的程序代碼而掌握的,這些"前輩"包括: Olin Shivers, Jamie Zawinski, Kyle Jones, Barry Warsaw, Roland McGrath, Richard Stallman本人(當然得有他)和許多其他程序員。 |
$ pwd /home/c-aries/source/glib $ cat url http://ftp.gnome.org/pub/gnome/sources/glib/2.16/glib-2.16.6.tar.bz2 http://ftp.gnome.org/pub/gnome/sources/glib/2.16/glib-2.16.6.md5sum $ wget -c -i url |
$ tar xvf glib-2.16.6.tar.bz2 $ cd glib-2.16.6 |
$ mkdir mybuild $ cd mybuild $ ../configure --prefix=`pwd`/work $ make $ make install |
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) # define G_GNUC_EXTENSION __extension__ #else # define G_GNUC_EXTENSION #endif |
-ansi Specify the standard to which the code should conform. Currently CPP knows about C and C++ standards; others may be added in the future. -pedantic Issue all the mandatory diagnostics listed in the C standard. Some of them are left out by default, since they trigger frequently on harmless code. |
G_GNUC_EXTENSION typedef unsigned long long guint64; |
$ pkg-config --cflags mybuild/work/lib/pkgconfig/glib-2.0.pc -I/home/c-aries/source/glib/glib-2.16.6/mybuild/work/include/glib-2.0 -I/home/c-aries/source/glib/glib-2.16.6/mybuild/work/lib/glib-2.0/include |
$ pkg-config --libs mybuild/work/lib/pkgconfig/glib-2.0.pc -L/home/c-aries/source/glib/glib-2.16.6/mybuild/work/lib -lglib-2.0 |
$ pwd /home/c-aries/develop $ cvs co test-glib $ cd test-glib/ $ make $ ./main The Largest Number Of 64 Bits: 18446744073709551615 |
$ cvs co -p test-glib cvs checkout: Updating test-glib =================================================================== Checking out test-glib/Makefile RCS: /home/c-aries/cvs/test-glib/Makefile,v VERS: 1.1.1.1 *************** CC = gcc CFLAGS = -Wall -Werror -Wcast-align -g LDFLAGS = MAINOBJECT = main.o opt.o TESTOBJECT = test.o GLIBHOME = /home/c-aries/source/glib/glib-2.16.6/mybuild/work GLIBPC = $(GLIBHOME)/lib/pkgconfig/glib-2.0.pc GLIBCFLAGS = `pkg-config --cflags $(GLIBPC)` GLIBLIBS = `pkg-config --libs $(GLIBPC)` all: main main: $(MAINOBJECT) $(CC) $(LDFLAGS) $(GLIBLIBS) $(MAINOBJECT) -o $@ test: $(TESTOBJECT) $(CC) $(LDFLAGS) $(TESTOBJECT) -o $@ main.o: main.c $(CC) $(CFLAGS) $(GLIBCFLAGS) -c $< opt.o: opt.c $(CC) $(CFLAGS) -c $< test.o: test.c $(CC) $(CFLAGS) -c $< clean: rm -f *.o *~ *.log a.out main test .PHONY: all clean =================================================================== Checking out test-glib/main.c RCS: /home/c-aries/cvs/test-glib/main.c,v VERS: 1.2 *************** #include <stdio.h> #include <stdlib.h> #include <glib.h> #include "opt.h" int main(int argc, char *argv[]) { options_init(); options_deal(argc, argv); g_print("The Largest Number Of 64 Bits: %" G_GUINT64_FORMAT "\n",\ G_MAXUINT64); exit(EXIT_SUCCESS); } =================================================================== Checking out test-glib/opt.c RCS: /home/c-aries/cvs/test-glib/opt.c,v VERS: 1.1.1.1 *************** #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include "opt.h" struct options opt; static void show_usage(); static void show_usage() { printf("usage: main [options]\n\ -h 列印該幫助信息\n\ -v 顯示程序內部提示\n"); } void options_init() { opt.verbose = 0; } void options_deal(int argc, char *argv[]) { int my_opt; while ((my_opt = getopt(argc, argv, "hv")) != -1) { switch(my_opt) { case 'h': show_usage(); exit(EXIT_SUCCESS); case 'v': opt.verbose = 1; break; default: show_usage(); exit(EXIT_FAILURE); } } } =================================================================== Checking out test-glib/opt.h RCS: /home/c-aries/cvs/test-glib/opt.h,v VERS: 1.1.1.1 *************** #ifndef OPT_H #define OPT_H struct options { int verbose; }; void options_init(); void options_deal(int argc, char *argv[]); #endif $ |
glib
[火星人 ] 學習glib源碼包已經有316次圍觀