㈠ 如何安裝 glibc-2.15.tar
編譯步驟:
下載glibc-2.15.tar.gz和補丁包glibc-ports-2.15.tar.gz
解壓
$mv glibc-ports-2.15 glibc-2.15/ports
$mkdir glibc-build-2.15 &&cd glibc-build-2.15
$ ../glibc-2.15/configure \
--prefix=/usr/local/glibc_mips \
CC=mipsel-linux-gcc \
--host=mipsel-linux \
--build=i686-pc-linux-gnu \
--enable-add-on=nptl \
libc_cv_forced_unwind=yes \
libc_cv_c_cleanup=yes \
libc_cv_mips_tls=yes \
libc_cv_gnu99_inline=yes
ok,沒問題
$make &&make install
大功告成
##########################################################################
下面是我編譯時的過程和遇到的問題及解決:
##########################################################################
$tar xvf glibc-2.16.0.tar.bz2
$cd glibc-2.16.0
$./configure --prefix=/usr/local/glibc //先不加其他選項,除了安裝路徑,一切默認,網上一般配置arm的選項如下 --prefix=$HOME/usr/arm --with-headers=$HOME/usr/arm/glibc/arm-linux-glibc/include --with-libs=$HOME/usr/arm/glibc/arm-linux-glibc/lib
報錯:
configure: error: you must configure in a separate build directory
很奇怪的問題,必須配置一個構建目錄,剛開始以為是安裝目錄為創建
$mkdir /usr/local/glibc
問題仍然存在,網路之
$mkdir ../glibc-build && cd ../glibc-build
$../glibc-2.16.0/configure --prefix=/usr/local/glibc
出現新的問題:
configure: WARNING:
*** These auxiliary programs are missing or incompatible versions: msgfmt
*** some features will be disabled.
*** Check the INSTALL file for required versions.
checking LD_LIBRARY_PATH variable... contains current directory
configure: error:
*** LD_LIBRARY_PATH shouldn't contain the current directory when
*** building glibc. Please change the environment variable
*** and run configure again.
第一個警告不用管它,第二個LD_LIBRARY_PATY也會有錯?我的這個路徑用了多少天了。仔細看提示,不應包含當前路徑。打開~/.bash_profile
$cat ~/.bash_profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib export LD_LIBRARY_PATH
這也沒當前路徑啊。還是網路吧。
一個兄弟的解釋是這樣「LD_LIBRARY_PATH不能以終結符作為開始和最後一個字元,不能有2個終結符連在一起,我的LD_LIBRARY_PATH為 :/usr/local/firefox:/usr/local/firefox,只要在前面加上一個路徑,不讓:出現在第一個字元就可以了 」
原來如此,第一個字元不能是":",修改~/.bash_profile
export LD_LIBRARY_PATH=/usr/local/lib export LD_LIBRARY_PATH
$../glibc-2.16.0/configure --prefix=/usr/local/glibc
ls一下,發現,當前目錄生成了Makefile等一堆東西
$make && make install
沒問題
下一步開始交叉編譯
$mkdir ../glibc-build-mips && cd ../glibc-build-mips
$ ../glibc-2.16.0/configure --prefix=/usr/local/glibc_mips CC=mipsel-linux-gcc --host=mips
出現新的問題:
configure: running configure fragment for add-on libidn
configure: running configure fragment for add-on nptl
*** The GNU C library is currently not available for this platform.
*** So far nobody cared to port it and if there is no volunteer it
*** might never happen. So, if you have interest to see glibc on
*** this platform visit
*** http://www.gnu.org/software/libc/porting.html
*** and join the group of porters
看起來像是需要path,下載glibc-ports-2.16.tar.gz,放在源碼包目錄,解壓
$ ../glibc-2.16.0/configure \
--prefix=/usr/local/glibc_mips \
CC=mipsel-linux-gcc \
CXX=mipsel-linux-g++ \
--host=mips \
--enable-add-ons=/home/hb/code/glibc/glibc-ports-2.16.0/sysdeps/mips
仍然報錯:
configure: error: fragment must set $libc_add_on_canonical
改為:
$ ../glibc-2.16.0/configure \
--prefix=/usr/local/glibc_mips \
CC=mipsel-linux-gcc \
CXX=mipsel-linux-g++ \
--host=mips \
--enable-add-ons
報錯:
configure: error: The mipsel is not supported.
這樣不行,谷歌半天,總算知道補丁怎麼用的了。把補丁目錄拷到glibc目錄下,改名為ports
$mv glibc-ports-2.16.0/ glibc-2.16.0/ports
$../glibc-2.16.0/configure \
--prefix=/usr/local/glibc_mips \
CC=mipsel-linux-gcc \
CXX=mipsel-linux-g++ \
--host=mipsel-linux \
--build=i686-pc-linux-gnu \
--enable-add-on
繼續報錯:
configure: error:
*** These critical programs are missing or too old: ld as
*** Check the INSTALL file for required versions.
這個問題可折騰死我了。弄了好半天,就是不行,最後google發現,原來是ld和as版本不對,不是太高就是太低。
configure中找到$AS --version
發現版本是這么匹配的2.1*.*
$mipsel-linux-ld
GNU ld (GNU Binutils) 2.18.50.20080908
原來是這樣,在configure版本號那一行修改,最後的括弧前面加入
|2.18.50.×
as那一行也同樣修改
然後
$make
開始編譯,看起來不錯
好半天後,編譯也報錯了
In file included from ../include/uchar.h:1,
from mbrtoc16.c:23:
../wcsmbs/uchar.h:47:5: error: #error "<uchar.h> requires ISO C11 mode"
In file included from ../include/uchar.h:1,
from mbrtoc16.c:23:
../wcsmbs/uchar.h:52: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'char16_t'
../wcsmbs/uchar.h:53: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'char32_t'
../wcsmbs/uchar.h:61: error: expected ')' before '*' token
../wcsmbs/uchar.h:66: error: expected declaration specifiers or '...' before 'char16_t'
../wcsmbs/uchar.h:73: error: expected ')' before '*' token
../wcsmbs/uchar.h:78: error: expected declaration specifiers or '...' before 'char32_t'
mbrtoc16.c:37: error: expected ')' before '*' token
make[2]: *** [/home/hb/code/glibc/glibc-build-mips/wcsmbs/mbrtoc16.o] 錯誤 1
make[2]:正在離開目錄 `/home/hb/code/glibc/glibc-2.16.0/wcsmbs'
make[1]: *** [wcsmbs/subdir_lib] 錯誤 2
make[1]:正在離開目錄 `/home/hb/code/glibc/glibc-2.16.0'
make: *** [all] 錯誤 2
看看這個頭文件咋回事
$ vim ../glibc-2.16.0/wcsmbs/uchar.h
#if defined __GNUC__ && !defined __USE_ISOCXX11
/* Define the 16-bit and 32-bit character types. Use the information
provided by the compiler. */
# if !defined __CHAR16_TYPE__ || !defined __CHAR32_TYPE__
# if defined __STDC_VERSION__ && __STDC_VERSION__ < 201000L
# error "<uchar.h> requires ISO C11 mode"
# else
# error "definitions of __CHAR16_TYPE__ and/or __CHAR32_TYPE__ missing"
# endif
# endif
明白了,原來是需要c11支持,mipsel-linux-gcc -v一下,我的支持c99.原來如此。暫時沒招了,我還做不到修改c11的支持,只剩兩個辦法,不用這個glibc版本或者重新編譯一個支持c11的交叉編譯器。編譯器需要做的比較多,暫時先換個低點的版本吧。
下載galibc-2.15版本
重復上面步驟,解壓tar包
解壓ports包
$mv glibc-ports-2.15 glibc-2.15/ports
$mkdir glibc-build-2.15 &&cd glibc-build-2.15
$ ../glibc-2.15/configure \
--prefix=/usr/local/glibc_mips \
CC=mipsel-linux-gcc \
--host=mipsel-linux \
--build=i686-pc-linux-gnu \
--enable-add-on=nptl \
libc_cv_forced_unwind=yes \
libc_cv_c_cleanup=yes \
libc_cv_mips_tls=yes \
libc_cv_gnu99_inline=yes
ok,沒問題
$make &&make install
庫已經編好了,但是不能直接使用,必須再用新的庫重編一遍編譯器才行。
上一篇
㈡ 在C語言里,關於庫函數中各種數學函數的代碼。
你說的就是庫函數的源碼,也就是glibc,源碼在ftp://ftp.gnu.org/gnu/glibc可以下到,比如下載ftp://ftp.gnu.org/gnu/glibc/glibc-2.9.tar.gz,打開後就可以看到你需要的各種庫的具體實現代碼,比如在string中的strcat.c中就有
char*strcat(dest,src)
char*dest;
constchar*src;
{
char*s1=dest;
constchar*s2=src;
reg_charc;
/*Findtheendofthestring.*/
do
c=*s1++;
while(c!='