GerritGroot
Technical User
Hi,
Somehow I'm doing something wrong in my module as soon as I nest functions. I'll try to explain it by an example:
Imagine that my main program is main.f90:
Using the module math_mod.f90:
When I compile the above using gfortran:
gfortran -o ./math_mod.o -c ./math_mod.f90
gfortran -o ./main.o -c main.f90
The objects are being made without errors, however when I try to link them to an executable using:
gfortran -o main.exe ./*.o
I get the error:
undefined referene to sqrd_
If I only use the "Sqrd" function in the module it works all fine, but as soon as I nest them to make the "Fourth" function I get this linking error.
There must be something very basic that I'm doing wrong, but what???
Thanks for your help,
Gerrit
Somehow I'm doing something wrong in my module as soon as I nest functions. I'll try to explain it by an example:
Imagine that my main program is main.f90:
Code:
PROGRAM Test
USE Math
IMPLICIT NONE
REAL :: y,x=2.2
y=Fourth(x)
WRITE(*,*)x,y
READ(*,*)
END PROGRAM Test
Using the module math_mod.f90:
Code:
MODULE Math
IMPLICIT NONE
CONTAINS
FUNCTION Fourth(x)
REAL :: Fourth
REAL, INTENT(IN) :: x
REAL :: Sqrd
Fourth=Sqrd(x)*Sqrd(x)
END FUNCTION Fourth
FUNCTION Sqrd(x)
REAL :: Sqrd
REAL, INTENT(IN) :: x
Sqrd=x**2
END FUNCTION Sqrd
END MODULE Math
When I compile the above using gfortran:
gfortran -o ./math_mod.o -c ./math_mod.f90
gfortran -o ./main.o -c main.f90
The objects are being made without errors, however when I try to link them to an executable using:
gfortran -o main.exe ./*.o
I get the error:
undefined referene to sqrd_
If I only use the "Sqrd" function in the module it works all fine, but as soon as I nest them to make the "Fourth" function I get this linking error.
There must be something very basic that I'm doing wrong, but what???
Thanks for your help,
Gerrit