Msys2 -> f951.exe: Fatal Error: Reading module '...' at line 2 column 1: Unexpected EOF

I am trying to use a module with gfortran 8.2.0 under Win 10 + Portable Msys2. This problem does not show up with gfortran 7.3.0 under Ubuntu 18.04LTS. After failing to compile my actual case, I put together

My MWE or MCVE:

Compilation

How can I solve this?

Upvotes: 3

Views: 7904

Answers (2)

Andrew House
Andrew House

Reputation: 31

It seems that this problem is caused by the search rule of msys2. This error will emerge as long as there exists any invalid path before the location of msys64\mingw64\bin in path of Environment Variables.

You can solve this problem either by removing those invalid paths or moving the mingw64 path location to the first one.

Upvotes: 0

tukan
tukan

Reputation: 17347

I recommend upgrading your msys2 installation. I have tried your MCVE on my gfortran 8.3.0-2 (mingw64/mingw-w64-x86_64-gcc-libgfortran 8.3.0-2 (mingw-w64-x86_64-toolchain)) and windows 7 (I don't have a virtual machine with win10 yet) with msys2.

I updated my msys2 installation with pacman -Syu. Next I searched for gfortran via pacman -Ss gfortran and picked the x64 version.

To check I had the fortran:

$ whereis gfortran
gfortran: /mingw64/bin/gfortran.exe

I did this:

main.f90:

module testmod
implicit none
integer :: Npuntos=10             ! def 1
double precision :: PI=3.1415296  ! def 2
double precision :: T=4.0         ! def 3
double precision :: T0=4.0        ! def 4
double precision :: S0=4.0        ! def 5
end module testmod

and

mod_testmod.f90:

program main_prog
use testmod
implicit none
integer :: j
end program main_prog

Here is the log:

Ugun@thor MSYS /c/t/fortran
$ gfortran -g -c -o mod_testmod.o mod_testmod.f90

Ugun@thor MSYS /c/t/fortran
$ ls
main.f90  mod_testmod.f90  mod_testmod.o  testmod.mod

Ugun@thor MSYS /c/t/fortran
$ gfortran -g -c -o main.o main.f90

Note: for the sake of completness I have tried all the combinations you reported as failed and all were successful.

  1. I think you should upgrade your MSYS2 env.
  2. Upgrade your gfortran installation.

Upvotes: 1

Related Questions