系统:Ubuntu 14.04
安装:glib-2.54.3
1.下载
http://ftp.acc.umu.se/pub/GNOME/sources/glib/
2.配置
./configure
问题 1:
configure: error: Package requirements (libffi >= 3.0.0) were not met:
No package 'libffi' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
No package 'libffi' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
解决方法:
sudo apt-get install libffi-dev
问题 2:
configure: error: *** Could not find libmount
解决方法:
./configure --enable-libmount=no
最后的配置命令,解决问题2,并且指定安装位置:
./configure --enable-libmount=no --prefix=install-prefix
3.编译
make
4.安装
rm -rf /install-prefix/include/glib.h /install-prefix/include/gmodule.h #删除之前安装的头文件
make install # install GLIB
5.简单使用
5.1 查看安装路径下的文件:

5.2 编写测试程序:
//hello.c
#include <glib.h>
#include <glib/gprintf.h>
int main(int argc, char** argv)
{
g_printf("hello world!!!\n");
return 0;
}
#include <glib/gprintf.h>
int main(int argc, char** argv)
{
g_printf("hello world!!!\n");
return 0;
}
5.3 编译
gcc -L/install-prefix/lib -I/install-prefix/include/glib-2.0 -I/install-prefix/lib/glib-2.0/include/ hello.c -o hello -lglib-2.0
如果是默认安装也可以使用
gcc hello.c `pkg-config --cflags --libs glib-2.0` -o hello
进行编译。
5.4 执行

注:本文章为作者原创, 如需转载请告知,并注明出处。