The order of options to gcc
(and other compilers) matters.
gcc -Wall main.c $(pkg-config --libs --cflags glib-2.0) -o main
And I don't really like the above. You should learn how to use GNU make. At the very least, put the compile flags, then the sources, then the object files, then the libraries (from high level to low level).
gcc -Wall $(pkg-config --cflags glib-2.0) main.c
$(pkg-config --libs glib-2.0) -o main
Better yet, have a Makefile
starting with
CC=gcc
CFLAGS= -Wall $(pkg-config --cflags glib-2.0)
LIBES= $(pkg-config --libs glib-2.0)
And compiling as root should be avoided. Only installation should require root privilege...
You probably want to add -g
(compiler flag for debugging information). Once the program is ready and nearly bugfree, replace it with -O2
(optimizations) and do some serious testing again!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…