gcc --version # 查看gcc版本 sudo yum update gcc -y # 只能升到4.4.7
参考Prerequisites for GCC,须要GMP, MPFR, MPC, ISL, CLooG。php
我先查看了下系统,发现原生就装了GMP等,以下命令。但以后"gcc ./configure"有错,仍须要下载安装GMP等。详见"Issue 1"。html
yum list installed gmp # 查看gmp安装了没
ps: 上述问题,应该是要"yum install gmp-devel"来安装开发环境就能够了。本来只有运行环境,因此是"Issue 1"里提到的找不到头文件。MPFR,MPC等也一样。linux
缺乏的均可以先到ftp://gcc.gnu.org/pub/gcc/infrastructure/下找找看。ios
# 建立个目录,都下载到这里 mkdir -p ~/Env/gcc; cd ~/Env/gcc # GMP, MPFR, MPC wget https://ftp.gnu.org/gnu/gmp/gmp-5.1.3.tar.bz2 wget http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.gz wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz tar jxvf gmp-5.1.3.tar.bz2 tar zxvf mpfr-3.1.2.tar.gz tar zxvf mpc-1.0.2.tar.gz # 都直接安装到默认路径下 cd gmp-5.1.3 ./configure --enable-cxx CPPFLAGS=-fexceptions # 选项缘由"Issue 2" make; make install cd ../mpfr-3.1.2; ./configure make; make install cd ../mpc-1.0.2; ./configure make; make install cd ..
若是GMP、MPFR、MPC在"./configure"时用"--prefix"指定了安装路径,则"gcc ./configure"须要加上"--with-xxx"等选项。由GMP > MPFR > MPC依赖顺序,也须要加上"--with-xxx"选项。可见参考34。c++
以后"gcc ./configure"(见"3) 安装"),我这儿仍有错,ISL与CLooG也要安装:测试
sudo gedit config.log # 查看日志,搜索"error" # issue: configure: error: C++ compiler missing or inoperational # 没有C++编译器 yum install gcc-c++ # issue: conftest.cpp:11:2: error: #error -static-libstdc++ not implemented # 没有C,C++静态库 yum install glibc-static libstdc++-static -y # 但报"No package libstdc++-static available",即没有-static-libstdc++源,问题仍存在。 # "checking whether g++ accepts -static-libstdc++ -static-libgcc"时报出的,可忽略。 # issue: conftest.c:10:25: error: isl/version.h: No such file or directory # 没有ISL wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.12.2.tar.bz2 tar jxvf isl-0.12.2.tar.bz2 cd isl-0.12.2; ./configure make; make install cd .. # issue: ./conftest: error while loading shared libraries: libisl.so.10: cannot open shared object file: No such file or directory # 在"/usr/local/lib"目录下,怎么就它找不到。加到"/etc/ld.so.conf"或用"LD_LIBRARY_PATH"。 vi /etc/ld.so.conf # 添加"/usr/local/lib" ldconfig # 重建/etc/ld.so.cache # 自问:于**Issue 1**里,已经单独在"/etc/ld.so.conf.d"下建个"*.conf"添加过"/usr/local/lib",怎么没效果呢? # 自答:以后安装的ISL,没从新ldconfig,因此找不到了?当时没查,不能确认。用如下命令: strings /etc/ld.so.cache | grep libisl # 查看 # 以后,删除了"/etc/ld.so.conf"内的添加,也再也不有该问题。 # issue: conftest.c:10:27: error: cloog/version.h: No such file or directory # 没有CLooG wget ftp://gcc.gnu.org/pub/gcc/infrastructure/cloog-0.18.1.tar.gz tar zxvf cloog-0.18.1.tar.gz cd cloog-0.18.1; ./configure make; make install cd .. # issue: conftest.c:15: error: 'choke' undeclared (first use in this function) # "checking for version 0.17.0 of CLooG"失败报出的,没问题。
若是安装时都自定义了路径,记得要将库路径都添加到"/etc/ld.so.conf"内。ui
# GCC wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.gz # 下载gcc源码 tar zxvf gcc-4.8.2.tar.gz # 解压源码 cd gcc-4.8.2 # 进入源码目录 # 生成Makefile,./configure --help看帮助,或看参考2 ./configure \ --prefix=/usr/local/gcc-4.8.2 \ --enable-languages=c,c++,go \ --disable-multilib make; make install # 编译并安装 # 重建gcc软连接 cd /usr/bin mv gcc gcc4.4.7 mv g++ g++4.4.7 ln -s /usr/local/gcc-4.8.2/bin/gcc gcc ln -s /usr/local/gcc-4.8.2/bin/g++ g++ # 添加gcc的man路径 vi /etc/man.config # 添加"MANPATH /usr/local/gcc-4.8.2/share/man" # 因为未卸载旧的,我这"man gcc"能够查看帮助,因此未添加。 # 若是再添加,不肯定会有什么影响。
Issue 1:this
king for the correct version of gmp.h... no configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+. Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify their locations..net
开始没注意"king for the correct version of gmp.h... no",先以下查了gmp等的位置。c++11
rpm -qa|grep gmp # 查看gmp安装了哪些 rpm -ql gmp-4.3.1-7.el6_2.2.i686 # 查看gmp安装位置
而后添加"--with-gmp"等,没效果。
难道库搜索路径没包括"/usr/lib",却包括了"/usr/local/lib"(以后安装了GMP等后,却能经过"./configure")?
因而,查看"/etc/ld.so.conf",其"include ld.so.conf.d/*.conf",但继续查看发现都不包含上述两路径,不是很明白。而后,自行添加了下。
cd /etc/ld.so.conf.d touch mine.conf # 或用vi,发现我不会用了 gedit mine.conf # 添加/usr/lib与/usr/local/lib ldconfig # 重建/etc/ld.so.cache
注意,安装ISL后,执行ldconfig会有以下错误,重装换个低版本也同样。试着解决没成功,而后忽视了。相似提问:Pacman/ldconfig - wrong magic bytes。
ldconfig: /usr/local/lib/libisl.so.10.2.2-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
以后,发现GMP等头文件没有:
find / | grep gmp.h
因此仍是要安装的。
Issue 2:
# 没有PPL wget ftp://ftp.cs.unipr.it/pub/ppl/releases/1.1/ppl-1.1.tar.bz2 tar jxvf ppl-1.1.tar.bz2 cd ppl-1.1; ./configure make; make install cd ..
"ppl ./configure"时,
若是"gmp ./configure"未设置"--enable-cxx":
checking for the GMP library version 4.1.3 or above... no configure: error: Cannot find GMP version 4.1.3 or higher. GMP is the GNU Multi-Precision library: see http://www.swox.com/gmp/ for more information. When compiling the GMP library, do not forget to enable the C++ interface: add --enable-cxx to the configuration options.
若是"gmp ./configure"未设置"CPPFLAGS=-fexceptions":
configure: WARNING: CANNOT PROPAGATE EXCEPTIONS BACK FROM GMP: *** MEMORY EXHAUSTION MAY RESULT IN ABRUPT TERMINATION. *** This is OK, if you do not plan to use the bounded memory capabilities *** offered by the PPL. Otherwise, if you are using GCC or the Intel C/C++ *** compiler, please make sure you use a version of GMP compiled with the *** `-fexceptions' compiler option. *** To build such a version, you can configure GMP as follows: *** CPPFLAGS=-fexceptions ./configure --enable-cxx --prefix=/usr/local
按要求重编了GMP,但以上这个警号还会在。
"ppl make"时,
mp_std_bits.defs.hh:47: error: redefinition of 'class std::numeric_limits<__gmp_expr<__mpz_struct [1], __mpz_struct [1]> >' /usr/local/include/gmpxx.h:3271: error: previous definition of 'class std::numeric_limits<__gmp_expr<__mpz_struct [1], __mpz_struct [1]> >' mp_std_bits.defs.hh:108: error: redefinition of 'class std::numeric_limits<__gmp_expr<__mpq_struct [1], __mpq_struct [1]> >' /usr/local/include/gmpxx.h:3308: error: previous definition of 'class std::numeric_limits<__gmp_expr<__mpq_struct [1], __mpq_struct [1]> >'
ppl-0.11与gmp-5.1.3有冲突,改成ppl-1.1便可。
ppl-0.11: ftp://gcc.gnu.org/pub/gcc/infrastructure/ppl-0.11.tar.gz
test.cc:
#include <iostream> #include <string> #include <vector> template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { for (auto& el : vec) { os << el << ' '; } return os; } int main() { std::vector<std::string> words = { "Hello", "from", "GCC", __VERSION__, "!" }; std::cout << words << std::endl; }
而后:
g++ -std=c++11 test.cc -o test ./test
输出:"Hello from GCC 4.8.2 !"。
p.s. 升级GCC后,动态库连接问题