centos 編譯安裝glib

來源:互聯網
上載者:User

下載最新的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]: Entering directory `/root/Desktop/glib-2.26.0/gio/tests'  

/usr/bin/msgfmt -o test.mo ./de.po; /  

  •         /bin/mkdir -p de/LC_MESSAGES; /  
  •         cp -f test.mo de/LC_MESSAGES  
  • ./de.po:15: 關鍵字“msgctxt”未知  
  • ./de.po:15:8: parse error  
  • /usr/bin/msgfmt: 發現 2 處致命錯誤
  • 原因:需要升級gettext package的庫,操作如下:

    1.  wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.1.1.tar.gz  
    2. tar xvzf gettext-0.18.1.1.tar.gz   
    3. cd gettext-0.18.1.1  
    4. ./configure  
    5. make  
    6. make install  
    7. ldconfig  

     這裡在網上隨便找了一個test:

    /* until.c 用來測試實用功能 */
    #include <glib.h>
    int main(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

      

     

     

     

    相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.