Mei Win
Mei Win

Reputation: 31

"Can't open module file 'types.mod'" when compiling a main.f90 program

A quick run down:

How do I fix this issue? All help will be greatly appreciated.

Here's the main.f90 code:

module read_write
use types
use analytic_functions, only : second_derivative_f
use euler_formulas, only : euler_3points
implicit none

private
public read_input, write_derivatives

contains

I don't know if this would help but here's the 'types.f90' code:

module types
! The iso_fortran_env is an intrinsic module that should already be
! inside of your compiler
use iso_fortran_env
implicit none
integer, parameter :: sp = REAL32 !< single precision kind
integer, parameter :: dp = REAL64 !< double precision kind
integer, parameter :: qp = REAL128!< quadruple precision kind
real(dp), parameter :: pi=acos(-1.0_dp)!< &pi; = 3.141592...
end module types

Upvotes: 3

Views: 1873

Answers (1)

user13963867
user13963867

Reputation:

Note: these .mod files are more or less like C headers, they allow the compiler to check types at compile time, which was usually not possible in Fortran 77 when compiling from several source files. They are created when you compile the modules.

Hence, you have first to compile the modules. Note that to compile and link main.f90, you also have to pass the object files to gfortran, otherwise the linker won't be able to resolve references to functions from these modules.

gfortran -c types.f90
gfortran -c analytic_functions.f90
gfortran -c euler_formulas.f90
gfortran main.f90 types.obj analytic_functions.obj euler_formulas.obj

The gfortran compiler is also able to compile all files at once, but you must pass the files in a specific order: if program or module B uses module A, then B.f90 must be after A.f90 on the command line. This is necessary for the compiler to find the .mod files when they are used.

gfortran types.f90 analytic_functions.f90 euler_formulas.f90 main.f90

Upvotes: 3

Related Questions