升级gcc的原因
报错信息
>>> import tensorflow
Traceback (most recent call last):
....
ImportError: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.7' not found (required by ...)
During handling of the above exception, another exception occurred:
....
ImportError: Traceback (most recent call last):
...
ImportError: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.7' not found (required by ...)
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
gcc升级至4.9
注意:别安装gcc-4.9.0版本,因为前方有个坑!!!
#下载gcc的安装文件
wget ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.9.4.tar.bz2
##安装gcc、c++编译器以及内核文件
yum -y install gcc gcc-c++ kernel-devel
#和其它一些可能的文件
yum install gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel
#安装C和C++的静态库
yum install -y glibc-static libstdc++-static
#将gcc-4.9.0.tar.bz2解压到/usr/local/src目录中(当然你也可以指定其他目录)
tar jxvf gcc-4.9.4.tar.bz2 -C /usr/local/src
#切换至gcc源程序根目录
cd /usr/local/src/gcc-4.9.4
#下载一些必备的依赖程序
#安装gcc需要下载诸如gmp、mpfr、mpc等依赖文件,执行download_prerequisites将会自动下载这些软件并解压到当前目录
./contrib/download_prerequisites
#先创建一个目录 (也可以自行指定其他目录)用于存放编译后的程序文件
mkdir /usr/local/build/gcc-4.9.4
#切换至编译后的程序文件存放目录
cd /usr/local/build/gcc-4.9.4
#调用gcc源程序的configure(后面的参数选项可根据需要自行修改),用于配置gcc
/usr/local/src/gcc-4.9.4/configure --prefix=/usr/local/build/gcc-4.9.4 --enable-checking=release --enable-languages=c,c++ --disable-multilib
#gcc 编译参数说明:
#--enable-languages //指定 gcc 能编译哪些语言的文件,每种语言用逗号分隔, 例如 c,c++,java
#--disable-multilib //默认gcc 能在32位系统上将代码编译成64位程序,或者在64位系统上编译成32位程序,如果加上这个编译选项则表示关闭这个gcc的交叉编译功能。
#编译gcc源程序
make -j4
make install
echo 'export PATH="/usr/local/build/gcc-4.9.4/bin:$PATH"' >> ~/.bash_profile
. ~/.bash_profile
gcc -v
报错信息
checking LIBRARY_PATH variable... contains current directory
configure: error:
*** LIBRARY_PATH shouldn't contain the current directory when
*** building gcc. Please change the environment variable
*** and run configure again.
make[2]: *** [configure-stage2-gcc] Error 1
make[2]: Leaving directory `/home/abdul/cc02/gcc-4.6.2/src-infra/obj-gcc'
make[1]: *** [stage2-bubble] Error 2
make[1]: Leaving directory `/home/abdul/cc02/gcc-4.6.2/src-infra/obj-gcc'
解决办法
# unset [-fv][变量或函数名称]
# -f 仅删除函数。
# -v 仅删除变量。
unset LIBRARY_PATH
#后续步骤一样
/usr/local/src/gcc-4.9.4/configure --prefix=/usr/local/build/gcc-4.9.4 --enable-checking=release --enable-languages=c,c++ --disable-multilib
make -j4
make install
echo 'export PATH="/usr/local/build/gcc-4.9.4/bin:$PATH"' >> ~/.bash_profile
. ~/.bash_profile
gcc -v
最后
echo `export LD_LIBRARY_PATH="/usr/local/build/gcc-4.9.4/lib64:$LD_LIBRARY_PATH"` >> ~/.bash_profile
. ~/.bash_profile
echo $LD_LIBRARY_PATH
由于有的软件是依赖老版的gcc,所以不能轻易删掉以前的gcc,那么如何切换使用不同版本的gcc呢?此处笔者推荐使用命令alternatives(maintain symbolic links determining default commands)
参考链接:
https://stackoverflow.com/questions/8565695/error-compiling-gcc-4-6-2-under-ubuntu-11-10
https://stackoverflow.com/questions/20357033/how-to-fix-program-name-usr-lib-x86-64-linux-gnu-libstdc-so-6-version-cxx
http://www.runoob.com/linux/linux-comm-unset.html
https://stackoverflow.com/questions/23494103/version-cxxabi-1-3-8-not-found-required-by
https://stackoverflow.com/questions/43419795/how-to-install-tensorflow-on-anaconda-python-3-6
解决类似 /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21’ not found 的问题