本文是我源码安装GCC工具链的过程以及遇到的问题,希望能解决你遇到的问题。如果有什么问题, 请在本文下方评论, 或者发邮件至syyxy@outlook.com. 欢迎交流探讨。
1)
svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc
2)
cd gcc; mkdir build
3)
../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
4) 执行configure 报如下错误:
缺少 GMP MPFR MPC
5)http://www.multiprecision.org/mpc/download.html
http://www.mpfr.org/mpfr-2.4.2/
6)在一个新的目录下载解压上述文件
wget ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.1.tar.xz
wget http://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.gz
wget https://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz
xz -d gmp-6.1.1.tar.xz
tar -zxvf mpc-1.0.2.tar.gz
tar -zxvf mpfr-2.4.2.tar.gz
tar -xvf gmp-6.1.1.tar
7) 在gcc 目录中创建 gmp,mpc,mpfr文件夹,然后将解压出的文件拷贝到其中(注意不要安装,直接拷贝)、
mkdir gmp mpc mpfr
cp -rf mpc-1.0.2/* /home/yangxiaoyu/sourceCode/gcc/mpc
cp -rf mpfr-2.4.2/* /home/yangxiaoyu/sourceCode/gcc/mpfr
cp -rf mp/* /home/yangxiaoyu/sourceCode/gcc/gmp/
8) 继续在build目录执行 :
../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
发现如下错误:
mpfr 的版本必须是 必须 > 3.1.0,于是:
wget http://www.mpfr.org/mpfr-current/mpfr-4.0.1.tar.gz
将gcc/ mpfr目录下的文件删除,将新的解压出来拷贝进去。
9) 继续执行configure 遇到如下错误:
安装m4
wget http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.bz2
tar -xjf m4-1.4.16.tar.bz2
cd m4-1.4.16/
cd build
../configuremake sudo make install
继续,
./configure过程中报 ./stdio.h:477:1: error: 'gets' undeclared here (not in a function)
解决:
vim ./build/lib/stdio.h +477
使用
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif
替换:
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
继续执行:../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib . 会在build目录生成Makefile
9) 然后在build 目录make -j4.
会得到如下错误:
这时需要安装 autoconf:
sudo apt-get install autoconf
然后执行:
sudo autoreconf -ivf
然后报错如下:
需要 2.64 版本的 autoconf
wget https://ftp.gnu.org/gnu/autoconf/autoconf-2.64.tar.bz2
tar -xjf autoconf-2.64.tar.bz2
mkdir build;cd build
../configure --prefix=/usr/bin/autoconf-2.64
然后在gcc 目录(build 的上一级目录)执行:
sudo /usr/bin/autoconf-2.64/bin/autoreconf -ivf
切记不要在build目录执行该命令,会报错:
autoreconf: `configure.ac' or `configure.in' is required
10) 继续 make, 报如下错误:
打开文件发现 mul.c中的 mpfr_fmma 是static ,我将该函数改名字为 mpfr_fmma_mul
继续编, 报错:
安装 flex
sudo apt-get install flex
继续 make,
报错如下:
在 libmpc.a 中 缺少 mpfr_add_one_ulp 函数的实现, 首先在gcc 目录下查找 该定义:
find * -type f ! -name "*.a" ! -name "*.o" |xargs grep "mpfr_add_one_ulp" -s -n
得到如下结果:
yangxiaoyu@yangxiaoyu-HP-EliteBook-8460p:~/sourceCode/gcc$ find * -type f ! -name "*.a" ! -name "*.o" |xargs grep "mpfr_add_one_ulp" -s -n
mpc/src/mpc-impl.h:63:#define MPFR_ADD_ONE_ULP(x) mpfr_add_one_ulp (x, GMP_RNDN)
mpfr/NEWS:100:- Old, deprecated macros mpfr_add_one_ulp and
mpfr_sub_one_ulp removed.
mpfr/NEWS:157:- The mpfr_add_one_ulp and mpfr_sub_one_ulp macros (which are obsolete and
匹配到二进制文件 mpfr/doc/mpfr.info
mpfr/doc/mpfr.texi:4210:Macros @code{mpfr_add_one_ulp} and @code{mpfr_sub_one_ulp} have been
mpfr/ChangeLog:2949:Old, deprecated macros mpfr_add_one_ulp and mpfr_sub_one_ulp removed.
mpfr/ChangeLog:33791:[NEWS] inform the users that mpfr_add_one_ulp and mpfr_sub_one_ulp will be
mpfr/ChangeLog:61048:Remove mpfr_add_one_ulp from MPFR library.
mpfr/ChangeLog:79585:mpfr_add_one_ulp and mpfr_sub_one_ulp changed.
yangxiaoyu@yangxiaoyu-HP-EliteBook-8460p:~/sourceCode/gcc$
mpfr_add_one_ulp 由 MPFR_ADD_ONE_ULP 定义而来, 于是继续查找 MPFR_ADD_ONE_ULP :
yangxiaoyu@yangxiaoyu-HP-EliteBook-8460p:~/sourceCode/gcc$ find * -type f ! -name "*.a" ! -name "*.o" |xargs grep "MPFR_ADD_ONE_ULP" -s -n
mpc/src/tan.c:197: MPFR_ADD_ONE_ULP (mpc_realref (x));
mpc/src/tan.c:198: MPFR_ADD_ONE_ULP (mpc_imagref (x));
mpc/src/tan.c:199: MPFR_ADD_ONE_ULP (mpc_realref (y));
mpc/src/tan.c:200: MPFR_ADD_ONE_ULP (mpc_imagref (y));
mpc/src/tan.c:250: MPFR_ADD_ONE_ULP (mpc_realref (x));
mpc/src/tan.c:252: MPFR_ADD_ONE_ULP (mpc_imagref (x));
mpc/src/mpc-impl.h:63:#define MPFR_ADD_ONE_ULP(x) mpfr_add_one_ulp (x, GMP_RNDN)
mpc/src/mpc-impl.h:84: ((f) ? MPFR_ADD_ONE_ULP (rop), MPFR_SIGNBIT (rop) : 0)
mpc/src/sqrt.c:293: MPFR_ADD_ONE_ULP (mpc_realref (a));
mpc/src/sqrt.c:301: MPFR_ADD_ONE_ULP (mpc_imagref (a));
mpc/src/sqrt.c:309: MPFR_ADD_ONE_ULP (mpc_imagref (a));
yangxiaoyu@yangxiaoyu-HP-EliteBook-8460p:~/sourceCode/gcc$
发现并没有 MPFR_ADD_ONE_ULP 的实现,于是百度该函数发现 http://www.mpfr.org/mpfr-current/mpfr.html 告诉我们:
之前在 8) 中, mpfr 的版本必须大于3.1.0. 因此这里看起来只能修改mpc的版本。 将 http://www.multiprecision.org/mpc/download.html 所有的版本(截止到现在最新版本为 1.0.3)下载下来, 所有的版本都调用了mpfr_add_one_ulp, 这就自相矛盾了。 我这边在mpfr-2.4.2版本的 mpfr.h 中发现了该宏的定义 :
#define mpfr_add_one_ulp(x,r)
(mpfr_sgn (x) > 0 ? mpfr_nextabove (x) : mpfr_nextbelow (x))
#define mpfr_sub_one_ulp(x,r)
(mpfr_sgn (x) > 0 ? mpfr_nextbelow (x) : mpfr_nextabove (x))
将其拷贝到gcc/mpfr/mpfr.h 中。
然后继续make
.
..
.
.
.
超长时间的编译
.
.
.
.
make 完成后,
sudo make install
完成安装!!
yangxiaoyu@yangxiaoyu-HP-EliteBook-8460p:~/sourceCode/gcc/build$ gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i686-pc-linux-gnu/8.0.1/lto-wrapper
目标:i686-pc-linux-gnu
配置为:../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
线程模型:posix
gcc 版本 8.0.1 20180409 (experimental) (GCC)
yangxiaoyu@yangxiaoyu-HP-EliteBook-8460p:~/sourceCode/gcc/build$
原文链接: https://www.cnblogs.com/syyxy/p/8846751.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/272382
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!