Clicky

Fortran Wiki
Compiling and linking modules

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Compiling and linking modules

The following example illustrates how to use the GNU Fortran compiler for compiling and linking modules.

Files

Example module

!> \\file testModule.f
module mathModule
 implicit none
 private
 real, public, parameter :: &
 pi = 3.1415 , &
 e = 2.7183 , &
 gamma = 0.57722
end module mathModule

Example main program

!> \\file mainProg.f
program testing
 use mathModule
 implicit none
 print *, "pi:", pi, "e:", e, "gamma:", gamma 
end program testing

Compiling and linking

At first compile both files and produce object files (*.o) and the module file (mathmodule.mod). Note that the ordering of the files is not important here.

$ gfortran -ffree-fortran -c testModule.f mainProg.f
$ ls
mainProg.f mainProg.o testModule.f testModule.o mathmodule.mod

Linking is done by

$ gfortran testModule.o mainProg.o
$ ls
a.out mainProg.f mainProg.o testModule.f testModule.o mathmodule.mod 
Created on July 3, 2018 09:16:53 by Mr Blue? (91.16.88.222) (1197 characters / 0.0 pages)
Edit | Views: Print | TeX | Source | Linked from: Object-oriented programming

AltStyle によって変換されたページ (->オリジナル) /