![]() |
|||
| 隨手行文 | 閒語集 | 過客留言 | 飛鴿傳書 | |||
作者: rock (遊手好閒的石頭成)
E-mail: shirock@educities.edu.tw
主要開發工具的版本如下(沒有更新過)
下列則是另外抓回來安裝的,屬於 RedHat 所附的套件。
為什麼要 GNU C Library 2.0.7 :
因為在 GNU C Library 2.0.7 中,除了提供更好的 function 外, 也支援了 pthread ,所以要在 Slackware 中使用 pthread 就需要先安裝 GNU C Library 2.0.7 。
在 Slackware (或Linux) 中,原本的主要 C Library (稱為 libc)版本 是 libc.so.5.3.12 ,而 GNU C Library 2.0.7 則是 libc.so.6 。
按 FAQ 中的說法是:
-----------------
For Linux there are three major libc versions:
libc-4 a.out libc
libc-5 original ELF libc
libc-6 GNU libc
-------------------
在 RedHat 5.1 中,已經將主要的 C Library 改成 libc.so.6 了,所以 RedHat 5.1 的使用者,不用再自行抓取 GNU C Library 2.0.7 來安裝了, 事實上我用的 GNU C Library 2.0.7 就是從 RedHat 的套件中抓下來,安 裝在 Slackware 上的。
在開始使用 rpm 前,需要先複製下列兩個檔案至適當位置:
/usr/lib/rpmrc -> /etc/rpmrc /usr/lib/rpmpopt -> /etc/popt
另外,還要自行建立一個目錄:
/var/lib/rpm
rpm 會將安裝的 package 的資訊,記錄在該目錄下。
在使用時,我碰到了兩個問題:
解決 rpm 的問題後,就可以開始安裝 GNU C Library 2.0.7 了, glibc-2.0.7-19.i386.rpm 是 libc.so.6 等 library 的 binary , glibc-devel-2.0.7-19.i386.rpm 則是配合 libc.so.6 的 header files, 及 新增函數的 manual ,要用 GNU C Library 2.0.7 寫程式,這兩個是最基本 的需要。
在用 rpm 安裝 glibc-devel-2.0.7-19.i386.rpm 時,安裝到後面,會發生一 點小問題,不過不妨礙使用就是了,我就不管它。
安裝完後,請 reboot ,以便載入新的 library 。
reboot後,可能在開機訊息中,會提示: ldconfig error: ld.so is not ELF 之類的訊息,不過一樣不用管它。
接著我們要修改 gcc 的設定,將預設的 C Library 從 libc.so.5 改為 libc.so.6 。
可自行參考 /usr/doc/glibc-2.0.7/FAQ 中第 2.6 節的內容,修改 gcc 的 設定檔,或直接按下列的說明。
先執行一次 gcc -v 找出 gcc 設定檔的位置,如下:
--------------------- # gcc -v Reading specs from /usr/lib/gcc-lib/i486-linux/2.7.2/specs gcc version 2.7.2 ---------------------
gcc 設定檔就是 /usr/lib/gcc-lib/i486-linux/2.7.2/specs 。
需要修改三個地方: (請用編輯器的搜尋功能找出)
修改完後,就算是安裝完成了,可以用下列的方式查證。
---------------------- #include#include void main() { printf("Hello.\n"); } ----------------------
# gcc -o hello hello.c
# ./hello Hello.
# ldd hello
libc.so.6 => /lib/libc.so.6 (0x40001000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00000000)
顯示的是 libc.so.6 及 ld-linux.so.2,所以確實用到的是 GNU C Library 2.0.7
---------------------------- #include#include #include #include #include void do_one_thing(int *); void do_another_thing(int *); void do_wrap_up(int,int); int r1=0, r2=0; void main() { pthread_t thread1, thread2; pthread_create(&thread1,NULL,(void*) do_one_thing, &r1); pthread_create(&thread2,NULL,(void*) do_another_thing, &r2); pthread_join(thread1,NULL); pthread_join(thread2,NULL); do_wrap_up(r1,r2); } void do_one_thing(int *i) { for( *i = 1; *i <= 100; (*i)++) write(1,"do one thing.",13); /* 如果用 printf() 或 outs() 這類使用緩衝區的函式,會受到 緩衝區的共用互斥影嚮,使得執行時顯示的訊息,不會出現交 叉出現的結果。 這也是 pthread 及 C Library 配合使用時,一個重要的效率 考量處:不當的使用 pthread ,反而會因系統呼叫的共用互斥 動作,折損了程式執行的效率,比使用單一thread的效率還差。 */ } void do_another_thing(int *i) { for( *i = 1; *i <= 100; (*i)++) write(1,"[1;31mdo anther thing.[m",26); } void do_wrap_up(int i, int j) { printf("%d,%d:%d\n",i,j,i+j); } --------------------------
# gcc -o mt -lpthread mt.c 因為要用 pthread ,所以需要link libpthread.so。
# mt 如果無誤的話,將會看到白字的'do one thing'和紅字的'do another thing'交 叉顯示,當然若你的電腦速度太快,也有可能已經執行完 thread1 後,才執行 到 thread2 ,看不出交叉顯示的結果。
# ldd mt
libpthread.so.0 => /lib/libpthread.so.0 (0x40001000)
^^^^^^^^^^^^^^^
libc.so.6 => /lib/libc.so.6 (0x4000e000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00000000)
無誤.
而在安裝 GNU C Library 2.0.7 前,就已存在的程式,在執行時並沒有受到 影嚮。
我看過 Slackware 3.5 套件中的內容,發現 Slackware 3.5 中,依然是使用 舊的 libc-5 (libc.so.5.4.44) 做為主要的 C Library ,所以本文內容一樣 適用。
|
Copyright (c) Shih Yuncheng <shirock@educities.edu.tw>. Rock's saying: http://home.educities.edu.tw/shirock/ Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the Invariant Sections being LIST THEIR TITLES, with the Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. A copy of the license is included in the section entitled "GNU Free Documentation License". http://www.fsf.org/licenses/fdl.html |
| 隨手行文 | 閒語集 | 過客留言 | 飛鴿傳書 | 石頭閒語 (http://home.educities.edu.tw/shirock/) |
| Copyright (C) 1999 - 2002 遊手好閒的石頭成 | 更新日期: 1998年10月1日 |