# Gfortran randomly failed to create valid \*.mod files based on the module name

**URL:** https://fortran-lang.discourse.group/t/gfortran-randomly-failed-to-create-valid-mod-files-based-on-the-module-name/7958
**Category:** Help
**Created:** [May 3, 2024, 4:36pm UTC](https://fortran-lang.discourse.group/t/gfortran-randomly-failed-to-create-valid-mod-files-based-on-the-module-name/7958 "2024-05-03T16:36:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![cyrilgandon](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/cyrilgandon/32/2151_2.png) [@cyrilgandon](https://fortran-lang.discourse.group/u/cyrilgandon)
#### Post date: [May 3, 2024, 4:36pm UTC](https://fortran-lang.discourse.group/t/gfortran-randomly-failed-to-create-valid-mod-files-based-on-the-module-name/7958/1 "2024-05-03T16:36:53Z")

</div>

This bug only appears on the laptop on my boss. I also found 2 unresolved issues online with similar problem. It is extremely hard to reproduce.  
Environnment is Windows + gfortran installed with msys2

**The Code :**

```auto
!! module.f90
module utils
    contains
    subroutine say_hello
      print *, 'Hello, World!'
    end subroutine
end module

```

```auto
!! program.f90
program hello
    use utils
    call say_hello()
end program

```

`gfortran -o foo module.f90 program.f90`

**The Error**

> f951.exe: Fatal Error: Reading module ‘utils.mod’ at line 1 column 26: Unexpected EOF compilation terminated.

**What I have test**

The file _utils.mod_ is generated, but seems kind of corrupted. It doesn’t work on cmd.exe or PowerShell, but the file is valid when generated in Git Bash.

Also, if you rename the module, sometimes it works, sometimes no.  
_utile.mod_ and _utils.mod_ failed. But _utila.mod_ and _utilz.mod_ works.  
_stdlib\_kinds.mod_ of the stdlib also failed.  
I try random forbidden word, like _cannabis.mod_ cannot be read, but _cannabiss.mod_ is ok.

It works fine on my machine, it only fails on 1 of our machine. I can’t reproduce it on any other device.

My first guess is windows preventing the generation of the mod file to be complete due to some naming convention? I was thinking about the antivirus filtering some mod file if the name contains some word? But this does not explain why it works on Git Bash and not cmd.exe.

Any hint to resolve, or try to resolve the problem would be veeeeeery welcomed 🙂

**Probably same issue but neither is resolved**

- [fortran - Msys2 -\> f951.exe: Fatal Error: Reading module '...' at line 2 column 1: Unexpected EOF - Stack Overflow](https://stackoverflow.com/questions/54824530/msys2-f951-exe-fatal-error-reading-module-at-line-2-column-1-unexpec)
- [[BUG] mingw64 gfortran (10.2) - module name can't be longer than 6 characters · Issue #6908 · msys2/MINGW-packages · GitHub](https://github.com/msys2/MINGW-packages/issues/6908)

---

<div class="post-metadata">

### Author: ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)
#### Post date: [May 3, 2024, 4:53pm UTC](https://fortran-lang.discourse.group/t/gfortran-randomly-failed-to-create-valid-mod-files-based-on-the-module-name/7958/2 "2024-05-03T16:53:56Z")

</div>

Works fine for me with gfortran 12.2 MinGW-w64 on Windows 7, from both cmd.exe and PowerShell.

My guess would be that this has something to do with the environment. Is the gfortran version/executable used in cmd.exe or PowerShell the same as under Git Bash?

---

<div class="post-metadata">

### Author: ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)
#### Post date: [May 3, 2024, 6:05pm UTC](https://fortran-lang.discourse.group/t/gfortran-randomly-failed-to-create-valid-mod-files-based-on-the-module-name/7958/3 "2024-05-03T18:05:36Z")

</div>

The \*.mod files produced by Gfortran are run-of-the-mill text files compressed by gzip. You can do

```auto
gzip -cd utils.mod

```

and you should see something similar to

```auto
GFORTRAN module version '15' created from module.f90
(() () () () () () () () () () () () () () () () () () () () () () () ()
() () ())

()

()

()

()

()

(2 'say_hello' 'utils' '' 1 ((PROCEDURE UNKNOWN-INTENT MODULE-PROC DECL
UNKNOWN 0 0 SUBROUTINE) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () ()
() 0 0)
3 'utils' 'utils' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN
UNKNOWN 0 0) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 0)
)

('say_hello' 0 2 'utils' 0 3)

```

---

<div class="post-metadata">

### Author: ![cyrilgandon](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/cyrilgandon/32/2151_2.png) [@cyrilgandon](https://fortran-lang.discourse.group/u/cyrilgandon)
#### Post date: [May 3, 2024, 8:58pm UTC](https://fortran-lang.discourse.group/t/gfortran-randomly-failed-to-create-valid-mod-files-based-on-the-module-name/7958/4 "2024-05-03T20:58:16Z")

</div>

That will be very useful, I will see what’s in there on Monday, thank you!

---

<div class="post-metadata">

### Author: ![MarDie](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mardie/32/54_2.png) [@MarDie](https://fortran-lang.discourse.group/u/MarDie)
#### Post date: [May 4, 2024, 2:22am UTC](https://fortran-lang.discourse.group/t/gfortran-randomly-failed-to-create-valid-mod-files-based-on-the-module-name/7958/5 "2024-05-04T02:22:26Z")

</div>

Since the behavior is observed sporadically, it is probably related to parallelization. In the context here, I could imagine that write to disk is buffered.  
@cyrilgandon are you compiling on a network drive or any other uncommon storage device?

---

<div class="post-metadata">

### Author: ![cyrilgandon](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/cyrilgandon/32/2151_2.png) [@cyrilgandon](https://fortran-lang.discourse.group/u/cyrilgandon)
#### Post date: [May 6, 2024, 11:21am UTC](https://fortran-lang.discourse.group/t/gfortran-randomly-failed-to-create-valid-mod-files-based-on-the-module-name/7958/6 "2024-05-06T11:21:08Z")

</div>

As expected, the mod files generated is an invalid zip file. Trying to decompress it renders an error:

> gzip: utils.mod: invalid compressed data–crc error  
> gzip: utils.mod: invalid compressed data–length error

The file is still processed anyway and looks like that:

```fortran
GFORTRAN module version '15' created from utils.f90
(() () () () () () () () () () () () () () () () () () () () () () () ()
() () ())

()

()

()

()

()

(2 'say_hello' 'utils' '' 1 ((PROCEDURE UNKNOWN-INTENT MODULE-PROC DECL
UNKNOWN 0 0 SUBROUTINE) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () ()
() 0 0)
3 'utils' 'utils' '' 1 ((MODULE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN
UNKNOWN 0 0INE) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () 0 UNKr
 () 0 UNKr
 () 0 UNKr
Uvo0 (0oO0 3)

```

There is effectively corrupted data if you compare to what it should looks like.

That starts at

```fortran
UNKNOWN 0 0INE) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () 0 UNKr

```

instead of

```fortran
UNKNOWN 0 0) () (UNKNOWN 0 0 0 0 UNKNOWN ()) 0 0 () () 0 () () () 0 0)

```

I’m compiling locally, no network or other weird thing.  
The next question is, what could trigger a failed zip action by gfortran when it tried to generate the .mod file?

Here is the failed _utils.mod_ file (renamed to avoid upload restriction)

[utils.mod.txt](https://fortran-lang.discourse.group/uploads/short-url/o6Pqhj5gjGd2Wkx5rHt60QrgSOX.txt) (219 Bytes)

Some research on an invalid generation of a zip files:

> sometimes caused by hardware issue on your side. For example failing harddrive, bad ram, network issues. Antivirus/firewall software is known to cause this also.

Also here is a diff between a compilation made under **cmd.exe** (left) and one made with **git bash** (right). Module name tested was _bbbb_ in this case (_b_, _bb_ and _bbb_ works fine).

 ![diff](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/f/fe9e0884ccad75a7e2a9cf7da7605d7b8de1697a.jpeg)

---

<div class="post-metadata">

### Author: ![cyrilgandon](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/cyrilgandon/32/2151_2.png) [@cyrilgandon](https://fortran-lang.discourse.group/u/cyrilgandon)
#### Post date: [May 6, 2024, 1:47pm UTC](https://fortran-lang.discourse.group/t/gfortran-randomly-failed-to-create-valid-mod-files-based-on-the-module-name/7958/7 "2024-05-06T13:47:50Z")

</div>

Installing gfortran from [Fortran, C, C++ for Windows](http://www.equation.com/servlet/equation.cmd?fa=fortran), the latest version, fixed the problem!
