安裝gcc4.8.5

安裝gcc4.8.5
1. g++ --version, 4.4.7不支持c++11
2. 升級gcc-c++, 下載gcc
    https://gcc.gnu.org/ 官網,鏡像下載地址https://gcc.gnu.org/mirrors.html,隨便找個鏡像下載就好了
    http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.8.5/gcc-4.8.5.tar.bz2    
3. 解壓,配置configure --prefix=yourprefix --enable-languages=c,c++
報錯:
configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.

去ftp://gcc.gnu.org/pub/gcc/infrastructure/下載所需的gmp-4.3.2.tar.bz2,mpc-0.8.1.tar.gz,mpfr-2.4.2.tar.bz2
分別解壓安裝
4. 從新配置,configure --prefix=yourprefix --enable-languages=c,c++ --with-gmp=gmp_path --with-mpc=mpc_path --with-mpfr=mpfr_path
再報錯:
checking for suffix of object files... configure: error: in `xxx/gcc-4.8.5/x86_64-unknown-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[2]: *** [configure-stage1-target-libgcc] Error 1
make[2]: Leaving directory `xxx/gcc-4.8.5'
不要打開xxx/gcc-4.8.5/config.log, 錯誤信息xxx/gcc-4.8.5/x86_64-unknown-linux-gnu/libgcc/config.log
共有3類錯誤信息:
    1. xgcc: error: unrecognized command line option '-V', fatal error: no input files
    2. xgcc: error: unrecognized command line option '-qversion', fatal error: no input files
    3. xxx/gcc-4.8.5/x86_64-unknown-linux-gnu/gcc/cc1: error while loading shared libraries: libmpc.so.2: cannot open shared object file: No such file or directory
Google了半天,結果是1/2類錯誤能夠忽略不計,3類錯誤咱們上面明明已經安裝了mpc,也指定了路徑,結果仍是找不到。。。
須要設置LD_LIBRARY_PATH,export LD_LIBRARY_PATH=mpc_path/lib
參考:http://blog.csdn.net/gaara_fan/article/details/7436940
5. 編譯,make -j8
報錯: Error 「gnu/stubs-32.h: No such file or directory」
緣由是缺乏32位libc開發包(http://stackoverflow.com/questions/7412548/error-gnu-stubs-32-h-no-such-file-or-directory-while-compiling-nachos-source)
yum install glibc-devel.i686
6. 再編譯,make -j8
等待…………………………………………………………………………
7. make install

8. 編寫helloworld.cpp,編譯: g++ helloworld.cpp
報錯: cc1plus: error while loading shared libraries: libmpc.so.2: cannot open shared object file: No such file or directory
add  LD_LIBRARY_PATH=mpc_path/lib
9. 運行,./a.out, OK
10. debug,gdb a.out
加斷點,run,Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.47.el6_2.9.x86_64 libgcc-4.4.6-3.el6.x86_64 libstdc++-4.4.6-3.el6.x86_64
參考:http://stackoverflow.com/questions/10389988/missing-separate-debuginfos-use-debuginfo-install-glibc-2-12-1-47-el6-2-9-i686
#debuginfo-install glibc-2.12-1.47.el6_2.9.x86_64 libgcc-4.4.6-3.el6.x86_64 libstdc++-4.4.6-3.el6.x86_64
n運行下一條,Single stepping until exit from function main, which has no line number info
參考:http://stackoverflow.com/questions/20474668/gdb-compile-with-g-option-but-single-stepping-until-exit-from-function-main
gdb版本過低……7.2-90.e16
http://ftp.gnu.org/gnu/gdb/下載新版本:gdb-7.6.tar.bz2
解壓安裝
再次調試,OK……html

相關文章
相關標籤/搜索