linux下編譯gcc6.2.0
在archlinx的下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://mirrors.ustc.edu.cn/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://bugs.archlinux.org/ --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.gnu.org/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.gnu.org/software/make/>
解決辦法
sudo apt-get install texinfo