一、安装glib
tar-xf glib-2.45.2.tar.xz
1、
进入目录文件中
./configure
make
make install
如果没什么问题就直接看第四部分。若有问题看参考下面
二、
./configure时的问题
gettext库下载地
http://ftp.gnu.org/pub/gnu/gettext/gettext-0.21.tar.xz
./configure
make
make install
1、zlib库的问题
如果发现报错,没有zlib库,ok,跑去安装zlib库,在终端输入sudo apt-get install zlib1g-dev
configure: error: *** Working zlib library and headers not found ***
自glib-2.23开始就需要zlib,zlib是提供数据压缩用的函式库。
也可以从zlib Home Site
http://www.zlib.net/ (下载地址在网页的中间部分)

我下载了个zlib-1.2.8.tar.gz,解压、进目录,三部曲:
./configure
make
make install
2、libffi问题
No package 'libffi' foundConsider adjusting the PKG_CONFIG_PATH environment variable if youinstalled software in a non-standard prefix.Alternatively, you may set the environment variables LIBFFI_CFLAGSand LIBFFI_LIBS to avoid the need to call pkg-config.See the pkg-config man page for more details.
我下载了libffi-3.2.1.tar.gz,解压、进目录,三部曲:./configuremakemake install
3、pkg-config问题
configure: error: The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config.
pkg-config能根据软件安装时软件的.pc配置文件路径找到相应的头文件路径和库文件路径。
我下载了pkg-config-0.29.1.tar.gz,解压、进目录,三部曲:
./configure
make
make install
如果第一步遇到如下错误:
configure: error: Either a previously installed pkg-config or "glib-2.0 >= 2.16" could not be found. Please set GLIB_CFLAGS and GLIB_LIBS to the correct values or pass --with-internal-glib to configure to use the bundled copy.
只需要:
./configure --with-internal-glib
4、pcre问题
configure: error: Package requirements (libpcre >= 8.13) were not met:No package 'libpcre' foundConsider adjusting the PKG_CONFIG_PATH environment variable if youinstalled software in a non-standard prefix.Alternatively, you may set the environment variables PCRE_CFLAGSand PCRE_LIBS to avoid the need to call pkg-config.See the pkg-config man page for more details.
我下载了pcre-8.38.tar.gz,解压、进目录,改动的三部曲:
./configure --enable-utf8 --enable-unicode-properties
makemake install
如果第一步只是./configure,到时候安装glib会继续报错:
checking for Unicode support in PCRE... no
configure: error: *** The system-supplied PCRE does not support Unicode properties or UTF-8.
所以第一步是为了解决Unicode、UTF-8的支持,仅限于pcre7.9以上版本
*安装pcre如果报错如下:
configure: error: You need a C++ compiler for C++ support
那是你所用的linux没支持c++编译,只需要:
apt-get install build-essential
**当安装好pcre后,输入pcretest -C来打印pcre的安装情况,一般输出如下:
PCRE version 8.38 2015-11-23Compiled with8-bit supportUTF-8 supportUnicode properties supportNo just-in-time compiler supportNewline sequence is LF\R matches all Unicode newlinesInternal link size = 2POSIX malloc threshold = 10Parentheses nest limit = 250Default match limit = 10000000Default recursion depth limit = 10000000Match recursion uses stack而如果报错为:pcretest: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directorypcretest: error while loading shared libraries: libpcreposix.so.0: cannot open shared object file: No such file or directory
这种情况好像大多数linux都会发生,只需要自己建立一个软链接即可:
ln -s /usr/local/lib/libpcre.so.1 /libln -s /usr/local/lib/libpcreposix.so.0 /lib
(如果之后还没用,可以考虑把/lib换/lib64)
三、
make时遇到的问题
1、
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
tmplen = strftime (tmpbuf, tmpbufsize, locale_format, &tm);
#pragma GCC diagnostic pop
进入glib中 打开gdate.c 删掉此行,复制以上代码
2、


sudo vi gdbusauth.c 查找文件路径#进入vi编辑器 根据错误找到第1295行 可在一般模式输入1302gg移动到该位置#在错误前输入 if(line != NULL)#:wq退出保存同理sudo vi gdbusmessage.c#进入vi编辑器 根据错误找到第2698行 可在一般模式输入2702gg移动到该位置 输入命令 vim +2698 gdbusmessage.c#在错误前输入 if(signature_str!= NULL)#:wq退出保存
四、测试安装是否成功
#include <glib.h>int main(void){g_print("Hello, world!\n");return 0;}
编译
gcc main.c `pkg-config --cflags --libs glib-2.0` -o hello
