I have two fortran files, one main.f90
that contains the following:
PROGRAM main
USE mtype
USE mconst
USE mrheo
IMPLICIT NONE
INTEGER :: i
REAL(DP) :: freq
COMPLEX(DPC) :: klove,hlove
nl=3
ALLOCATE(ire(nl),rho(nl),arad(nl),eta(nl),mu(nl),alpha(nl),zeta(nl),cdef(nl),eta_kv_rel(nl))
ire = (/0,1,1/)
rho = (/10d3,5d3,6d3/)
arad = (/3200d3,6000d3,6100d3/)
eta = (/1d-3,1d21,1d21/)
mu = (/1d-10,2d11,3d11/)
alpha = (/0.3d0,0.3d0,0.3d0/)
zeta = (/1.d0,1.d0,1.d0/)
cdef = (/0.2,0.2,0.2/)
eta_kv_rel = (/0.02,0.02,0.02/)
freq = 1e-6
call peltier(2,freq,klove,hlove)
write (*,'(2g20.10)') abs(klove),abs(abs(klove)/aimag(klove))
END PROGRAM main
And another file that contains the modules mfunc.f90
MODULE mtype
!==================================================
! Data type module
!==================================================
! Declares the parameters DP, DPC and I4B that are going it be used
! 1.0d0 makes it a double precision
!
IMPLICIT NONE
INTEGER, PARAMETER :: DP = KIND(1.0D0)
INTEGER, PARAMETER :: DPC = KIND((1.0D0,1.0D0))
INTEGER, PARAMETER :: I4B = SELECTED_INT_KIND(9)
END MODULE mtype
!==================================================
MODULE mconst
!==================================================
! Internal constants module
!==================================================
USE mtype
IMPLICIT NONE
! Physical constants
REAL(DP) :: kappa=6.674d-11,pi=4*atan(1.d0)
! Auxiliary variables
! iellid - if applied, the lithosphere is treated as elastic
INTEGER :: iellid=0 ! 0-VE lithosphere, 1-elastic lihosphere
INTEGER :: nlit=1 ! number of layers the litosphere consists of
! Common variables
!==================
INTEGER :: neq,np
REAL(DP) :: d
INTEGER,ALLOCATABLE :: indx(:)
COMPLEX(DPC),ALLOCATABLE :: a(:,:),b(:)
! Input arrays
INTEGER :: nl
INTEGER,ALLOCATABLE :: ire(:)
REAL(DP),ALLOCATABLE :: rho(:),arad(:),eta(:),mu(:),alpha(:),zeta(:)
REAL(DP),ALLOCATABLE :: eta_kv_rel(:),cdef(:)
COMPLEX(DPC),ALLOCATABLE :: muC(:)
REAL(DP) :: ksi,grav
END MODULE mconst
...
I have the two files inside the project folder of Visual Studio Code, but when I try to run the main.f90
file I get the following error:
Undefined symbols for architecture x86_64:
"___mconst_MOD_alpha", referenced from:
_MAIN__ in ccJ2kyNS.o
"___mconst_MOD_arad", referenced from:
_MAIN__ in ccJ2kyNS.o
"___mconst_MOD_cdef", referenced from:
_MAIN__ in ccJ2kyNS.o
"___mconst_MOD_eta", referenced from:
_MAIN__ in ccJ2kyNS.o
"___mconst_MOD_eta_kv_rel", referenced from:
_MAIN__ in ccJ2kyNS.o
"___mconst_MOD_ire", referenced from:
_MAIN__ in ccJ2kyNS.o
"___mconst_MOD_mu", referenced from:
_MAIN__ in ccJ2kyNS.o
...
So it looks like the main file doesn't connect to the modules file, but I'm not sure how to solve it (I'm using mac, with homebrew gcc and Visual Studio Code). I've been trying to find a solution for a while but still can't figure this one out (first time with Fortran, or at least trying to).