CentOS7 で提供されているGCCは「GCC 4.8.5」である

アプリケーションによってはこれ以上のバージョンが要求される場合がある。
なら別途GCCをコンパイルして用意するのが手なのだろうが、ハードルが高い。
なので、devtoolset パッケージを使って容易に 「GCC 4.9より新しいGCC」を使えるようにしてみた。

pkgs.orgを拝見すると

devtoolsetバージョン備考
devtoolset-3GCC version 4.9終了
devtoolset-4GCC version 5終了
devtoolset-6GCC version 6終了
devtoolset-7GCC version 7
devtoolset-8GCC version 8
devtoolset-9GCC version 9

の対応みたい。細かいバージョン番号は省いてます。GCC以外にも c++、gfortran が用意されている
インストール先は

/opt/rh/devtoolset-{3,4,6,7,8,9}/root/usr/{bin,lib,libexec,share}

と別の場所にルート(/)を置く感じで、まるで chroot みたい。

centos-sclo-rh リポジトリの登録

まずは devtoolsetパッケージが含まれるリポジトリ「centos-release-scl-rh」をインストールします。

[root@centos7 ~]# yum install centos-release-scl-rh

これで /etc/yum.repos.d に新たなリポジトリが追加されます
中身はこんな感じです.

[root@centos7 ~]# cat /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
# CentOS-SCLo-rh.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information
 
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
#baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/rh/
mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
 :
 :
[root@centos7 ~]#

このリポジトリの概要は「yum repolist -v centos-sclo-rh」コマンドで得られます
CentOS/devtoolset/repository

devtoolsetのインストール

ここでは最新のdevtoolsetをインストールしてみます(2101時点)

[root@centos7 ~]# yum install devtoolset-9
(これで gcc,g++,gfortran,make,binutilsらが同時にインストールされる)
(インストール先は [/opt/rh/devtoolset-9/] )
 
[root@centos7 ~]# 
  

使い方

インストールをしてとてすぐさま devtoolset のGCCが使えるわけではなく導入手続きが必要.

方法は2つあって、1つはsclコマンドで有効にする

[illya@centos7 ~]$ scl -l                # sclで使えるパッケージリスト
devtoolset-9
 
[illya@centos7 ~]$ scl enable devtoolset-9 "gcc --version"
gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
Copyright (C) 2019 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.
 
 
[illya@centos7 ~]$

「scl enable devtoolset-9 "gcc --version"」という事でdevtoolsetのgccを起動してみたが、これはこの一回限りです.
永続的にdevtoolsetの環境下に置きたいならシェルを呼び込みます

[illya@centos7 ~]$ scl enable devtoolset-9 bash
 
[illya@centos7 ~]$ gcc --version
gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
Copyright (C) 2019 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.
[illya@centos7 ~]$

これはログインシュルが bash なら 再度 bash を実行した形です.
明示的で分かりやすいのかもしれませんが、どうせなら立ち上げたshellが何もせずに devtoolset が有効になっているようにしたいなら「source」を使います

[illya@centos7 ~]$ source scl_source enable devtoolset-9

としてそのシェルをdevtoolsetで上書きさせるか、「.bashrc」に「source scl_source enable devtoolset-9」を記載するのもありかと

ここで whereis コマンドを使ってみると

[illya@centos7 ~]$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /opt/rh/devtoolset-9/root/usr/bin/gcc /usr/share/man/man1/gcc.1.gz
 
[illya@centos7 ~]$

となるので、基本はPATH環境変数の調整のみと思われる

そうなると

modulefile

EnvironmentModulesにdevtoolsetを食わせればアプリと連動して使えるのでは?と
っで作ってみた
ファイル名は「devtoolset-9」で

#%Module1.0
#
set devtoolset devtoolset-9
set PCP_DIR    /opt/rh/$devtoolset/root
 
setenv X_SCLS  $devtoolset
setenv PCP_DIR $PCP_DIR
 
prepend-path LD_LIBRARY_PATH $PCP_DIR/usr/lib64:$PCP_DIR/usr/lib:$PCP_DIR/usr/lib64/dyninst:$PCP_DIR/usr/lib/dyninst
prepend-path PATH            $PCP_DIR/usr/bin
prepend-path PKG_CONFIG_PATH $PCP_DIR/usr/lib64/pkgconfig
prepend-path INFOPATH        $PCP_DIR/usr/share/info
最新の60件
2025-02-17 2025-02-15 2025-02-14 2025-02-12 2025-02-03 2025-02-02 2025-02-01 2025-01-27 2025-01-26 2025-01-25 2025-01-24 2025-01-23 2025-01-20 2025-01-13 2025-01-12 2025-01-08 2024-12-30 2024-12-29 2024-12-22 2024-12-20 2024-12-17 2024-12-15 2024-12-14 2024-12-12 2024-12-11 2024-12-10 2024-12-09 2024-12-08 2024-11-28 2024-11-22 2024-11-15 2024-11-14 2024-11-12 2024-11-06 2024-11-05 2024-11-04 2024-11-02 2024-11-01 2024-10-28 2024-10-27 2024-10-23 2024-10-18 2024-10-17 2024-10-15 2024-10-14

edit


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2021-01-15 (金) 03:14:05