Linux7.3 glib-2.49安装记录

由于 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_64
readline-6.2-10.el7.x86_64
lua-5.1.4-15.el7.x86_64
libffi-3.0.13-18.el7.x86_64
libffi-devel-3.0.13-18.el7.x86_64
未安装软件包 libiconv
xz-5.2.2-1.el7.x86_64
glib2-2.46.2-4.el7.x86_64
cmake-2.8.12.2-2.el7.x86_64
popt-1.13-16.el7.x86_64
libnl-1.1.4-3.el7.x86_64
libevent-2.0.21-4.el7.x86_64
libevent-devel-2.0.21-4.el7.x86_64
openssl-devel-1.0.2k-8.0.1.el7.x86_64

libffi依赖包

ftp://sourceware.org/pub/libffi/libffi-3.0.13.tar.gz
tar -zxvf libffi-3.0.13.tar.gz
cd libffi-3.0.13/
./configure --prefix=/usr/local
make
make install

# ll /usr/local/lib | grep libffi
drwxr-xr-x 3 root root 20 11月 20 14:45 libffi-3.0.13

libiconv依赖包
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xvzf libiconv-1.14.tar.gz
cd libiconv-1.14
cd srclib
sed -i -e '/gets is a security/d' ./stdio.in.h
cd ..
注意不要建立独立目录,一定要安装在/usr/local目录下,不然安装glib时会报/usr/bin/ld: cannot find -liconv
./configure --prefix=/usr/local gl_cv_header_working_stdint_h=yes
make
make 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
make
make install

ln -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 --version
0.29.2

pcre安装
https://sourceforge.net/projects/pcre/files/pcre/
tar -zxvf pcre-8.39.tar.gz
cd pcre-8.39/
./configure --enable-utf8 --enable-unicode-properties
pcre-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 ................... : no
make
make install
ln -s /usr/local/lib/libpcre.so.1 /lib
ln -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.tar

mkdir /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=yes

esac
found_iconv=yes
if test "x$found_iconv" = "xno" ; then
as_fn_error $? "*** No iconv() implementation found in C library or libiconv" "$LINENO" 5
fi
fi

make阶段
ln -s /usr/local/lib/libffi-3.0.13/include/ffi.h /usr/local/include
ln -s /usr/local/lib/libffi-3.0.13/include/ffitarget.h /usr/local/include
ln -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

make
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
# ls
gio-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.pc

vim .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 ",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!

原文地址:https://www.cnblogs.com/perfei/p/7867252.html