gfortran cannot read its own creation
Asked Answered
A

0

9

I am trying to compile a code with gfortran. One of the first things that happens in the compilation is the creation of constants.mod. Soon after that gfortran tells me:

Fatal Error: Cannot read module file ‘constants.mod’ opened at (1), because it was created by a different version of GNU Fortran

Now here's the thing: This module file is created by the same gfortran that it's trying to read it. gfortran creates the thing itself and then 1 second later thinks the file was created by some other version! Any idea what's going on here?

You'll probably want to see the compile command:

mpif90 -c -O3 -ISDF/FORTRAN/include -I/usr/include -Iobj -Jobj -o obj/shared_data.o   src/core/shared_data.F90

shared_data.F90 contains the module constants at the top of the file.

EDIT: Here's the compile command followed by the full error message:

$> mpif90 -c -O3 -ISDF/FORTRAN/include -I/usr/include -Iobj -Jobj -o obj/shared_data.o  src/core/shared_data.F90
src/core/shared_data.F90:67:6:

   USE constants
      1
Fatal Error: Cannot read module file ‘constants.mod’ opened at (1), because it was created by a different version of GNU Fortran
compilation terminated.

UPDATE: I hope you'll agree this is weird. The file that is failing is in src/core. If I cd to src/core and issue this command:

mpif90 -c -O3 -I../../SDF/FORTRAN/include -I../../obj -J../../obj -o ../../obj/shared_data.o shared_data.F90

it compiles just fine! But then I clean everything out of the obj directory and I cd two levels up and issue:

mpif90 -c -O3 -ISDF/FORTRAN/include -Iobj -Jobj -o shared_data.o src/core/shared_data.F90

and it fails with the error I showed above! What is the difference??? Thanks.

Amelioration answered 6/11, 2015 at 14:23 Comment(18)
Where is exactly does the error occur? Where is (1)? Any chance there is another constants.mod in one of the include directories?Desiraedesire
@Raul Laasner Thanks for your comment. Please see my edit to the question.Amelioration
Any chance you used gfortran instead of mpif90 somewhere? They can actually be different.Chong
@Vladimir F Good thinking, but no. Thanks.Amelioration
@Amelioration Could you provide a minimal example with the contents of constants.f90 that reproduces the error?Desiraedesire
Edit: I meant the file containing the relevant module, which is not necessarily named constants.f90.Desiraedesire
@Amelioration Regarding your UPDATE, could it be possible that there is a constants.mod in the parent directory (but not in the subdirectory) that has been built with an older version of gfortran? Just to be sure, did you clean the build directory before attempting to recompile?Desiraedesire
@Raul Laasner Legitimate question, for sure. But, yes, I triple checked that. Thanks.Amelioration
I once also created an asset with "constants", namely for certain constants from the 2003 standard. With Fortran 2003 enabled, of course. Is there a chance that you did likewise? if so, try to print the constants and their names from a Fortran 2003 executable into a text-file, and use an editor (maybe even sed) to turn that into a valid Fortran 90 module.Cuzco
In the two command lines that worked there is no -I/usr/include.Taut
@terence hill You're right, but I should have said that I tested that too. Thanks.Amelioration
@Neeraj these problems are highly specific to your computer configuration, especially to the defaults of your Ubuntu upgrade. You should have rather asked a new question. But the OP might answer what helped him in his case...Chong
You could provide a minimal reproducible example, along with the compiler and SO versions so we can try to reproduce the bug.Conjuration
@VladimirF Sorry, Vladimir. It's been too long since I posted this, and I never had the problem again. Can't find any notes about it. Whatever solution I found is lost in the mists of time.Amelioration
@RodrigoRodrigues: Apologies. Should I provide the information in the comments?Systemize
@VladimirF: I observed similarities and felt that the another question would be redundent. But now I can see why my thoughts were inaccurate.Systemize
If your problem maches that from this question and adds to it somehow to clarify and make it replicable, you can edit the question by yourself. If you can’t do it, let us know in the comments.Conjuration
Have you tried to do find <path> -name constants.mod where <path> is changed to each and all possible paths searched via your use of the -I options? Or, have you tried locate constants.mod? It would also be helpful to see the output of mpif90 --version and gfortran --version.Hellbent

© 2022 - 2024 — McMap. All rights reserved.