I am currently working on a project involving Fortran and R, but the emphasis lies on the latter and not much coding is needed on the Fortran side. The aim is to create a dynamic library/shared object containing a Fortran subroutine to be loaded into R where it can be called.
Some background:
I have been given a Fortran file which contains a module called FitterModule.f95
and set up my Fortran subroutine in another Fortran file called zyzzyva.f95
. The subroutine is to utilise a function (al00
) that is within the module itself, and the code is as shown below:
subroutine al00wrapper(ca, d, answer)
use FitterModule
real :: ca, d, answer
answer = al00(ca, d)
return
end subroutine
After which, I proceeded to Macbook terminal to create the shared library, with the following commands:
gfortran -c zyzzyva.f95
gfortran -shared -o zyzzyva.so zyzzyva.o
gfortran -shared -o zyzzyva.so zyzzyva.o FitterModule.o
gfortran -shared -o zyzzyva.so FitterModule.o zyzzyva.o
However, each time I was given the following result:
Undefined symbols for architecture x86_64:
"_al00_", referenced from:
_al00wrapper_ in zyzzyva.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I have looked through posts that could have been similar to mine, but I am unable to figure out what is wrong still.
I am definitely very new to this and I appreciate if I could get some advice to resolve this issue, thank you!