if I understood the manual correctly it should work to creat a file containing a fortran module in a folder, say /path/mods/test_mod.f90 i.e. :
module test_mod
implicit none
save
contains
function prod(a,b) result(c)
real :: a,b,c
c=a*b
return
end function
end module
and compile it like:
gfortran -c test_mod.f90
And to create another file, say /path/bins/test_prog.f90, i.e:
program test_prog
use test_mod
real :: x,y,z
x=4e0
y=5e0
z=prod(x,y)
print*,z
end
and to compile it like:
gfortran -I/path/mods -o test_prog test_prog.f90
But for some reason I get a linker error on the mac saying:
Undefined symbols for architecture x86_64:
"___test_mod_MOD_prod", referenced from:
_MAIN__ in ccz1rsxY.o
ld: symbol(s) not found for architecture x86_64
collect2: ld gab 1 als Ende-Status zurück
Trying the same on a Suse Linux with Ifort I get:
/tmp/ifort2oZUKh.o: In function `MAIN__':
test_prog.f90:(.text+0x4d): undefined reference to `test_mod_mp_prod_'
Could someone please shine light in my darkness? Thanks! PS.: Writing both in one file of course works. Searching on the web I found some statemenst (that I quite frankly just not understood) saying that this might be related to static vs. dynamic linking.
You need to include the
.o
file as well. That is, you should compile this asThis worked and ran for me.
This
should produce two files:
test_mod.mod
andtest_mod.o
. Your other compilation statementcorrectly specifies the location in which to look for the
.mod
file but omits the.o
file. The.mod
file is a bit like a compiler-generated header file, it is used for compilation of any program units which use-associate the module, but the object file is needed for linking.The simplest (I think) fix is to write
but you may want to fiddle around with that.