Taitai
Taitai

Reputation: 616

cannot open fortran module in ubuntu

I am wring Fortran code in linux. My module file is in a *.f90 file. "program main" is in another *.f90 file. When I tried to compile my code in ubuntu "gfortran main.f90", errors said that can't find my module file.

program main
use module_name

Just now, I see someone say the files are compiled alphabetically. If this is the reason, then I am in big trouble. Because my program has called many subroutines and functions which are in different f90 files. So how to resolve this problem? Thanks.

Upvotes: 1

Views: 714

Answers (2)

Toby
Toby

Reputation: 21

Along with including the file name, use the specifier -I in gfortran to tell the compiler where to look for the file in case it can't find it. ex:
gfortran -I/path/to/module

Upvotes: 0

lakshayg
lakshayg

Reputation: 2173

Suppose you have a file containing the main program main.f90 and another file containing the module mod.f90. The correct way to compile and generate an executable named main will be

gfortran mod.f90 main.f90 -o main

You have not specified the module file while compiling therefore it is unable to compile

Upvotes: 2

Related Questions