安装前与下载
gcc的源码下载网址:http://ftp.gnu.org/gnu/gcc/
我下载的时候发现下载的特别慢,于是我复制了网址到手机浏览器下载,速度就快了。
安装gcc必备的几个包:m4、gmp、mpfr、mpc
第一个包可以通过apt install安装,输入下面命令。可以下载后三个压缩包。
./contrib/download_prerequisites
注意:上述四个软件包一定要按照顺序安装。
安装gmp-4.3.2
cd gcc-6.3.0/gmp-4.3.2 #进入文件夹
./configure --prefix=/usr/local/gmp-4.3.2
make
sudo make install
安装mpfr-2.4.2
cd gcc-6.3.0/mpfr-2.4.2/ #进入文件夹
./configure --prefix=/usr/local/mpfr-2.4.2 --with-gmp=/usr/local/gmp-4.3.2
make
sudo make install
安装mpc-0.8.1
cd gcc-6.3.0/mpc-0.8.1 #进入文件夹
./configure --prefix=/usr/local/mpc-0.8.1 --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2
make
sudo make install
安装gcc
cd gcc-6.3.0/ #进入文件夹
sudo ../gcc-6.3.0/configure --prefix=/usr/local/gcc-6.3.0 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2 --with-mpc=/usr/local/mpc-0.8.1
make
sudo make install
make的时间特别长,我用了近2个小时。
遇到的一些问题
make时遇到的问题
configure: error: cannot compute suffix of object files: cannot compile
解决办法: 将gmp、mpfr、mpc添加进系统变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib
source /etc/profile
error: dereferencing pointer to incomplete type ‘struct ucontext’
解决办法:
修改 md-unwind-support.h 文件的第 61 行,其中该文件位于 ./x86_64-pc-linux-gnu/libgcc 目录下。跳转到第 61 行,修改·struct ucontext *uc_ = context->cfa;
中的ucontext
为ucontext_t
struct ucontext_t *uc_ = context->cfa;
重新执行 make。
3. /libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc:158:23: fatal error: sys/ustat.h: No such file or directory
解决办法:
找到这个文件/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc,删除第158,#include <sys/ustat.h>
.
找到251行,在你的代码里,注释掉下面代码第一行。把// 包含的内容加进去。
//unsigned struct_ustat_sz = sizeof(struct ustat);
//
// Use pre-computed size of struct ustat to avoid <sys/ustat.h> which
// has been removed from glibc 2.28.
#if defined(__aarch64__) || defined(__s390x__) || defined (__mips64) \
|| defined(__powerpc64__) || defined(__arch64__) || defined(__sparcv9) \
|| defined(__x86_64__)
#define SIZEOF_STRUCT_USTAT 32
#elif defined(__arm__) || defined(__i386__) || defined(__mips__) \
|| defined(__powerpc__) || defined(__s390__)
#define SIZEOF_STRUCT_USTAT 20
#else
#error Unknown size of struct ustat
#endif
unsigned struct_ustat_sz = SIZEOF_STRUCT_USTAT;
//