0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【gfortran】特定のバージョンのgfortranを使う方法

Posted at

背景

  1. Atcoderのコンテスト参加時、自分の環境では正解が出力されているにも関わらず、Atcoder上では不正解になってしまった。
  2. 調べてみるとgcc,gfortranのバージョンが自分の環境とAtcoderで異なることが判明した。
    (自分の環境がgfortran-10で、Atcoderがgfortran-9であった。)
  3. バージョンの違いにより、出力結果が異なることがあるらしいので、自分の環境のバージョンをAtcoder上のバージョンと揃えたい。

目的

自分の環境とAtcoder上のgcc,gfortranバージョンを揃える。

検証環境

パソコン:MacBook Air 2020(M1)
OS:MacOS Ventura 13.3.1(a)
コンパイル環境:Docker+Vscoder+gfortran

手順

1. インストール可能なバージョンの確認

apt searchコマンドを使い、以下の通り該当するファイルを検索します。

sudo apt search '^gcc-[0-9]+$'

検索結果は以下の通りです。私の環境では、gcc-10とgcc-9が選べることがわかりました。

root:/workspaces/test# sudo apt search '^gcc-[0-9]+$'
Sorting... Done
Full Text Search... Done
gcc-10/stable 10.2.1-6 arm64
  GNU C compiler

gcc-9/stable 9.3.0-22 arm64
  GNU C compiler

2. 任意のバージョンのインストール

以下のコマンドによって、バージョンを指定してインストールが可能です。

sudo apt install gcc-9

インストールがうまくいってるかどうか、バージョン情報を見て確認します。

root@:/workspace/test# gcc-9 --version
gcc-9 (Debian 9.3.0-22) 9.3.0
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.

上記の通り、指定したバージョン(今回はgcc-9)がインストール出来ていることが確認できました。

3. gfortranのインストール

gccと同様の手順で、gfortranをバージョンを指定してインストールします。
今回はgfortran-9を選択します。
コマンドについては、下記の通りgccインストール時のものをgfortranに置き換えるだけです。

sudo apt install gfortran-9

インストールがうまくいってるかどうか、バージョン情報を見て確認します。
こちらも、gccインストール時のものをgfortranに置き換えるだけです。

root/workspaces/てtest#  gfortran-9 --version
GNU Fortran (Debian 9.3.0-22) 9.3.0
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.

上記の通り、指定したバージョンがインストール出来ていることが確認できました。

結果

下表の通りになります。完全にバージョンを一致させることはできませんでしたが、gcc-9に揃えることはできました。
(明確に恩恵を得られた場面がまだ集まり次第、追記します。)

環境 コンパイラ バージョン
Atcoder gfortran 9.2.1
【旧】自分の環境 gfortran 10.2.1
【新】自分の環境 gfortran 9.3.0
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?