使用glib.h时,Makefile的编写
使用glib.h,在编译时,可以使用以下两种方式
gcc -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0
或
gcc `pkg-config --cflags --libs glib-2.0`
当编写Makefile时,可能需要先生成*.o文件,再链接成可执行文件,即编译(生成*.o文件)和链接执行;
注意:编译的时候不需要-lglib-2.0,连接时才需要。
链接:-lglib-2.0
编译:-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
例:
SRC
=
main.o test.o
DST
=
test
COMP
=
-
I
/
usr
/
include
/
glib
-
2.0
-
I
/
usr
/
lib
/
glib
-
2.0
/
include
LINK
=
-
lglib
-
2.0
$(DST) : $(SRC)
g
++
$(LINK)
-
o $(DST) $(SRC)
main.o : main.c
g
++
$(COMP)
-
c main.c
test.o : test.c test.h
g
++
$(COMP)
-
c test.c test.h
c :
rm
-
fv
*
.o $(DST)
*~
*
.gch
内存泄露检测
linux下检测内存泄露的工具有很多,较为常见的包括yamd和ValGrind.
ValGrind,可以通过管理工具的新立得软件包管理器下载、安装;
在编译的时候,加入-g指令,然后执行
valgrind
--
tool
=
memcheck
--
leak
-
check
=
yes
--
show
-
reachable
=
yes .
/
test
./test表示生成的可执行文件
此时可以生成内存相关信息;