centos 编译安装glib

下载最新的glib.2.28.2

./configure --prefix=/usr

make clean && make && make install

(1)遇到问题

make的时候 缺少 magic.h头文件;这个头文件在centos的/usr/include/linux/里确实没有,我把http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/include/linux/magic.h 这个,直接拷贝到/usr/include/linux/下,顺利通过;

(2)make的时候出现这个错误: http://blog.csdn.net/saint1126/archive/2011/01/17/6147169.aspx

make[4]:Enteringdirectory`/root/Desktop/glib-2.26.0/gio/tests'

/usr/bin/msgfmt-otest.mo./de.po;/

  • /bin/mkdir-pde/LC_MESSAGES;/
  • cp-ftest.mode/LC_MESSAGES
  • ./de.po:15:关键字“msgctxt”未知
  • ./de.po:15:8:parseerror
  • /usr/bin/msgfmt:发现2处致命错误
  • 原因:需要升级gettext package的库,操作如下:

    1. wgethttp: //ftp.gnu.org/pub/gnu/gettext/gettext-0.18.1.1.tar.gz
    2. tarxvzfgettext-0.18.1.1.tar.gz
    3. cdgettext-0.18.1.1
    4. ./configure
    5. make
    6. makeinstall
    7. ldconfig

    这里在网上随便找了一个test:

    /* until.c 用来测试实用功能 */
    #include <glib.h>
    intmain(int argc, char *argv[])
    {
    GRand *rand;
    GTimer *timer;

    gint n;
    gint i, j;
    gint x = 0;
    rand = g_rand_new();//创建随机数对象
    for(n=0; n<20; n++)
    {//产生随机数并显示出来
    g_print("%d/t",g_rand_int_range(rand,1,100));
    }
    g_print("/n");
    g_rand_free(rand);//释放随机数对象
    //创建计时器
    timer = g_timer_new();
    g_timer_start(timer);//开始计时
    for(i=0; i<10000; i++)
    for(j=0; j<3000; j++)
    x++;//累计
    g_timer_stop(timer);//计时结束
    //输出计时结果
    g_print("%ld/tall:%.2f seconds was used!/n",x,g_timer_elapsed(timer,NULL));
    }

    使用这个编译:gcc -g `pkg-config --cflags --libs glib-2.0` t_glib.c -o t_glib

     

     

     

     

    猜你喜欢

    转载自djangofan.iteye.com/blog/1579868