Linux下编译GCC 6.2.0

2018-01-01 19:59:27 8158

在Arch Linx的下gcc已经更新到6.2.1了,Win10的WSL下还是gcc4.8。官方源没有比较新的版本,于是自己编译使用。


GCC6的几个新特性

GCC 6 现在的默认值是 C++ 14. GCC 6 现在包括 C++ Concepts.

C++运行时库现在支持特殊的数学函数 (ISO/IEC 29124:2010)

支持 C++17 的实验功能


准备


可以去gnu官网下载gcc6.2.0的源码,但国内访问速度比较慢。可以进中科大的镜像站去下载。


下载并解压


wget http://www.landui.com/gnu/gcc/gcc-6.2.0/gcc-6.2.0.tar.bz2

tar -xjvf gcc-6.2.0.tar.bz2

解压之后进入源码目录,运行下面命令下载依赖包


./contrib/download_prerequisites    #必须在源码根目录下运行此命令

编译gcc前需安装build-essential,bison,flex,texinfo。


生成Makefile


在源码目录下建立一个build目录(也可以在别的目录下),然后进入build目录运行configure脚本生成Makefile文件。


mkdir build && cd build

../configure --prefix=/usr/local/gcc6 --enable-checking=release --enable-languages=c,c++ --enable-threads=posix --disable-multilib

# --prefix=/usr/local/gcc6  指定安装路径

# --enable-languages=c,c++  支持的编程语言

# --enable-threads=posix    使用POSIX/Unix98作为线程支持库

# --disable-multilib        取消多目标库编译(取消32位库编译)

下面是archlinux自带gcc的编译配置命令(gcc -v查看)。


--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://www.landui.com/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release

如果配置的时候出现cannot find crt1.o cannot find crti.o cannot find crtn.o的错误,那么需要指定--build的参数,比如x86_64。


编译安装


上一步生成Makefile没有问题后,就可以直接编译安装了。


make -j8    #使用8个线程并行编译

make install    #安装(可能需要root权限)

错误与解决办法


makeinfo没有安装


/mnt/d/gcc/gcc-6.2.0/missing: 81: /mnt/d/gcc/gcc-6.2.0/missing: makeinfo: not found

WARNING: 'makeinfo' is missing on your system.

         You should only need it if you modified a '.texi' file, or

         any other file indirectly affecting the aspect of the manual.

         You might want to install the Texinfo package:

         <http://www.landui.com/software/texinfo/>

         The spurious makeinfo call might also be the consequence of

         using a buggy 'make' (AIX, DU, IRIX), in which case you might

         want to install GNU make:

         <http://www.landui.com/software/make/>

解决办法


sudo apt-get install texinfo


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: