疯狂的企鹅

Crazy.Rico's Blog


  • 首页

  • 归档

  • 关于

  • 标签

  • 分类

  • links

  • 搜索

Centos7编译安装gcc8.3.0

发表于 2020-04-23 更新于 2020-05-06 分类于 Python 阅读次数:
本文字数: 2.7k 阅读时长 ≈ 2 分钟

前言

GCC(GNU Compiler Collection,GNU编译器套件)是由GNU开发的编程语言译器。GNU编译器套件包括C、C++、 Objective-C、 Fortran、Java、Ada和Go语言前端,也包括了这些语言的库(如libstdc++,libgcj等。)

之前我们在Centos7中编译安装Python时, 添加[–enable-optimizations] 参数,由于GCC版本较低会报错安装失败

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
gcc -pthread     -Xlinker -export-dynamic -o python Programs/python.o libpython3.8.a -lcrypt -lpthread -ldl  -lutil -lm   -lm 
./python -E -S -m sysconfig --generate-posix-vars ;\
if test $? -ne 0 ; then \
echo "generate-posix-vars failed" ; \
rm -f ./pybuilddir.txt ; \
exit 1 ; \
fi
Could not import runpy module
Traceback (most recent call last):
File "/opt/Python-3.8.2/Lib/runpy.py", line 15, in <module>
import importlib.util
File "/opt/Python-3.8.2/Lib/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/opt/Python-3.8.2/Lib/contextlib.py", line 4, in <module>
import _collections_abc
SystemError: <built-in function compile> returned NULL without setting an error
generate-posix-vars failed
make[1]: *** [pybuilddir.txt] Error 1
make[1]: Leaving directory `/opt/Python-3.8.2'
make: *** [profile-opt] Error 2

查看本机gcc版本

1
2
3
4
5
# gcc --version
gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

在gcc版本较低的情况下可以通过两种方式安装成功Python

  1. disable –enable-optimizations option. the software can be compile and install successful.
  2. upgrade gcc version to 8.2.0.

安装gcc8.3

这里我们通过升级gcc来解决上面的报错问题

下载gcc源码包

1
2
# cd /usr/local/src
# wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-8.3.0/gcc-8.3.0.tar.xz

解压

1
# tar -xvJf gcc-8.3.0.tar.xz

下载依赖包

1
2
# cd gcc-8.3.0/
# ./contrib/download_prerequisites

执行命令后它会自动下载mpfr、gmp、mpc isl这4个库

编译安装

1
2
3
4
# mkdir build
# cd build
# ../configure --prefix=/usr/local/gcc --enable-languages=c,c++ --disable-multilib
# make && make install

编译安装时间确实很长,可以去看部电影再回来O(∩_∩)O哈哈~

修改软链接

备份下之前的版本,创建指向gcc8.3的软链接

1
2
3
4
5
# mv /usr/bin/gcc /usr/bin/gcc_old
# mv /usr/bin/g++ /usr/bin/g++_old

# ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
# ln -s /usr/local/gcc/bin/g++ /usr/bin/g++

查看gcc版本

1
2
3
4
5
6
7
8
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc/libexec/gcc/x86_64-pc-linux-gnu/8.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/gcc --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 8.3.0 (GCC)

这时我们的gcc版本已经显示为8.3了,再次回到Python安装,就可以愉快的玩耍了

1
2
3
# cd Python-3.8.2/
# ./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl
# make && make install

使用参数 –enable-optimizations 安装Python会慢一些,确实通过升级gcc版本可以解决上面的Python安装失败的问题。

1
2
3
4
5
# python3
Python 3.8.2 (default, Apr 23 2020, 08:38:06)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

参考

https://bugs.python.org/issue35074
https://www.jianshu.com/p/444169a3721a

-------------本文结束感谢您的阅读-------------
Crazy Rico wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
Crazy Rico 微信支付

微信支付

Crazy Rico 支付宝

支付宝

# centos7 # Python
Python学习笔记之简介
Anaconda简介
  • 文章目录
  • 站点概览
Crazy Rico

Crazy Rico

33 日志
17 分类
39 标签
RSS
GitHub FCC E-Mail 慕课网 阿里云
  1. 1. 前言
  2. 2. 安装gcc8.3
    1. 2.1. 下载gcc源码包
    2. 2.2. 解压
    3. 2.3. 下载依赖包
    4. 2.4. 编译安装
    5. 2.5. 修改软链接
    6. 2.6. 查看gcc版本
  3. 3. 参考
苏ICP备17004952号 © 2020 Crazy Rico | 90k | 1:22
由 Hexo 强力驱动 v3.9.0
|
主题 – NexT.Gemini v7.3.0
|
0%