Ubuntu12.04 64bitで最新版GCCをソースからビルド&インストール
ここを参考に...
http://domisan.sakura.ne.jp/article/ub120464_gcc/ub120464_gcc.html
○事前にインストール
sudo apt-get install build-essential git gcc-multilib texinfo flex bison policycoreutils libncurses5 libncurses5-dev
○GMP をインストール
※GCCのコンパイルに必要
http://gmplib.org/
の、「Download」の「gmp-5.1.2.tar.lz」をクリックする。
解凍する。
./configure
make
sudo make install
sudo ldconfig
make
sudo make install
sudo ldconfig
○MPFR をインストール
※GCCのコンパイルに必要
http://www.mpfr.org/mpfr-current/#download
の、「mpfr-3.1.2.tar.xz」をクリックする。
解凍する。
./configure
make
sudo make install
sudo ldconfig
make
sudo make install
sudo ldconfig
○MPC をインストール
※GCCのコンパイルに必要
http://www.multiprecision.org/index.php?prog=mpc&page=download
の、「Latest version」の「Version 1.0.1」をクリックする。
解凍する。
./configure
make
sudo make install
sudo ldconfig
make
sudo make install
sudo ldconfig
○GCC をインストール
※GCC自体のディレクトリでビルドしないようにする。
「No rule to make target `../.././gcc/libgcc.mvars'. Stop.」が発生する。
※makeにはかなりの時間がかかる。
git clone git://gcc.gnu.org/git/gcc.git
cd gcc
mkdir build
cd build
../configure --enable-languages=c,c++
make -j
sudo make install
cd gcc
mkdir build
cd build
../configure --enable-languages=c,c++
make -j
sudo make install
make -j
の時に
*** LIBRARY_PATH shouldn't contain the current directory
みたいに怒られた場合は
unset LIBRARY_PATH
をしてから,configureすると上手くいくかも
(参考:http://d.hatena.ne.jp/sugyan/20080626/1214425987)
○binutils をインストール
※./configureのオプション追加 2013/8/5
git clone git://sourceware.org/git/binutils.git
cd binutils
./configure --with-sysroot=/
make
sudo make install
cd binutils
./configure --with-sysroot=/
make
sudo make install
○GDB をインストール
git clone git://sourceware.org/git/gdb.git
cd gdb
./configure --disable-werror
make
sudo make install
cd gdb
./configure --disable-werror
make
sudo make install
---------
以上のインストールの後,適当なC++ソースをコンパイルして実行してみたところ,
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.18' not found
のエラーが発生した.
libstdc++.soは
/usr/local/lib64
にもあったため,
/etc/ld.so.conf.d/my_gnu.conf
というファイルを作成した後に
/usr/local/lib64
の1行を書きこんで,
sudo ldconfig
これでよくなった.
※2013/8/5
リンク時に
/usr/local/bin/ld: this linker was not configured to use sysroots
のエラーが出るのに対しては,binutilのconfigure時に--with-sysrootオプションをつけることによって解決.