由于 Linux系统较新,所在glib选择了较新的glib-2.49,安装过程遇到颇多错误,这里只记录正确的成功的安装记录。
# rpm -q ncurses readline lua libffi libffi-devel libiconv xz glib2 cmake popt libnl libevent libevent-devel openssl-devel
ncurses-5.9-14.20130511.el7_4.x86_64readline-6.2-10.el7.x86_64lua-5.1.4-15.el7.x86_64libffi-3.0.13-18.el7.x86_64libffi-devel-3.0.13-18.el7.x86_64未安装软件包 libiconv xz-5.2.2-1.el7.x86_64glib2-2.46.2-4.el7.x86_64cmake-2.8.12.2-2.el7.x86_64popt-1.13-16.el7.x86_64libnl-1.1.4-3.el7.x86_64libevent-2.0.21-4.el7.x86_64libevent-devel-2.0.21-4.el7.x86_64openssl-devel-1.0.2k-8.0.1.el7.x86_64libffi依赖包
ftp://sourceware.org/pub/libffi/libffi-3.0.13.tar.gztar -zxvf libffi-3.0.13.tar.gzcd libffi-3.0.13/./configure --prefix=/usr/localmakemake install
# ll /usr/local/lib | grep libffi
drwxr-xr-x 3 root root 20 11月 20 14:45 libffi-3.0.13libiconv依赖包
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gztar xvzf libiconv-1.14.tar.gzcd libiconv-1.14cd srclib sed -i -e '/gets is a security/d' ./stdio.in.hcd ..注意不要建立独立目录,一定要安装在/usr/local目录下,不然安装glib时会报/usr/bin/ld: cannot find -liconv./configure --prefix=/usr/local gl_cv_header_working_stdint_h=yesmakemake install pkg安装pkg-config is a helper tool used when compiling applications and libraries. It helps you insert the correct compiler options on the command line so an application can use gcc -o test test.c `pkg-config --libs --cflags glib-2.0` for instance, rather than hard-coding values on where to find glib (or other libraries). It is language-agnostic, so it can be used for defining the location of documentation tools, for instance.https://www.freedesktop.org/wiki/Software/pkg-config/
tar -zxvf pkg-config-0.29.2.tar.gz
cd pkg-config-0.29.2/./configure --enable-iconv=no --with-libiconv=gnu --with-internal-glib makemake installln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/libiconv.so.2# pkg-config --version0.29.2
pcre安装
https://sourceforge.net/projects/pcre/files/pcre/tar -zxvf pcre-8.39.tar.gzcd pcre-8.39/./configure --enable-utf8 --enable-unicode-propertiespcre-8.39 configuration summary:Install prefix .................. : /usr/local
C preprocessor .................. : gcc -E C compiler ...................... : gcc C++ preprocessor ................ : g++ -E C++ compiler .................... : g++ Linker .......................... : /usr/bin/ld -m elf_x86_64 C preprocessor flags ............ : C compiler flags ................ : -g -O2 -fvisibility=hidden C++ compiler flags .............. : -O2 -fvisibility=hidden -fvisibility-inlines-hidden Linker flags .................... : Extra libraries ................. :Build 8 bit pcre library ........ : yes
Build 16 bit pcre library ....... : no Build 32 bit pcre library ....... : no Build C++ library ............... : yes Enable JIT compiling support .... : no Enable UTF-8/16/32 support ...... : yes Unicode properties .............. : yes Newline char/sequence ........... : lf \R matches only ANYCRLF ......... : no EBCDIC coding ................... : no EBCDIC code for NL .............. : n/a Rebuild char tables ............. : no Use stack recursion ............. : yes POSIX mem threshold ............. : 10 Internal link size .............. : 2 Nested parentheses limit ........ : 250 Match limit ..................... : 10000000 Match limit recursion ........... : MATCH_LIMIT Build shared libs ............... : yes Build static libs ............... : yes Use JIT in pcregrep ............. : no Buffer size for pcregrep ........ : 20480 Link pcregrep with libz ......... : no Link pcregrep with libbz2 ....... : no Link pcretest with libedit ...... : no Link pcretest with libreadline .. : no Valgrind support ................ : no Code coverage ................... : nomakemake installln -s /usr/local/lib/libpcre.so.1 /libln -s /usr/local/lib/libpcreposix.so.0 /lib
glib安装
http://ftp.acc.umu.se/pub/GNOME/sources/glib/
xz -d glib-2.49.7.tar.xz
chown -R root.root *tar -xvf glib-2.49.7.tarmkdir /usr/local/glib-2.49.7
cd glib-2.49.7/./configure --prefix=/usr/local/glib-2.49.7 --with-libiconv=gnu LIBFFI_CFLAGS="-I/usr/local/include" LIBFFI_LIBS="-L/usr/local/lib -lffi"# vim ./configure
在7880行之上添加如下内容:found_iconv=yesesac
found_iconv=yes if test "x$found_iconv" = "xno" ; then as_fn_error $? "*** No iconv() implementation found in C library or libiconv" "$LINENO" 5 fifimake阶段
ln -s /usr/local/lib/libffi-3.0.13/include/ffi.h /usr/local/includeln -s /usr/local/lib/libffi-3.0.13/include/ffitarget.h /usr/local/includeln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/libiconv.so.2make
make install配置PKG-CONFIG
# find /usr/ -name pkgconfig/usr/lib64/pkgconfig/usr/share/pkgconfig/usr/local/lib/pkgconfig/usr/local/lib64/pkgconfig/usr/local/mysql/lib/pkgconfig/usr/local/glib-2.49.7/lib/pkgconfig# cd /usr/local/glib-2.49.7/lib/pkgconfig
# lsgio-2.0.pc gio-unix-2.0.pc glib-2.0.pc gmodule-2.0.pc gmodule-export-2.0.pc gmodule-no-export-2.0.pc gobject-2.0.pc gthread-2.0.pcvim .bash_profile
export PKG_CONFIG_PATH=/usr/local/glib-2.49.7/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/mysql/lib/pkgconfig:$PKG_CONFIG_PATH. ./.bash_profile编译测试
vim hello.c#include <stdio.h>#include <glib.h>int main(int argc, char** argv){ GList* list=NULL; list=g_list_append(list,"Hello world!"); list=g_list_append(list,"made by pcat"); list=g_list_append(list,"http://www.cnblogs.com/perfei/"); printf("The first item is %s\n",g_list_first(list)->data); return 0;}编译如下:
gcc hello.c -o hello $(pkg-config --cflags --libs glib-2.0)# ls -ltr | grep hello
-rw-r--r-- 1 root root 305 11月 20 16:47 hello.c-rwxr-xr-x 1 root root 8648 11月 20 17:05 hello# ./hello
The first item is Hello world!