Skip to content
Prev 177185 / 398503 Next

Compiling Fortran Subroutines as R Shared Objects on Mac OS-X

Chad R. Bhatti wrote:
Hi Chad,

I have an Intel mac running OS X 10.5 and I have compiled and used several
Fortran 77 and Fortran 90 subroutines, including MINPACK and MINOS, using R
CMD SHLIB.

I guess the first question I have, is have you installed the developer tools
from the OSX cd (the installer is located in the 'Optional Installs'
folder)? Pardon if this seems obvious, but it may explain the complaint
about the libgcc shared library.

Second, sometimes the options used in gfortran commands executed by R CMD
SHLIB can cause problems (specifically the -fPIC or -fno-common flags),
especially if modules or common blocks are involved in the fortran routines.
To get around this you can try running the compiler on the Fortran code
yourself and then R CMD SHLIB on the object code like so:

gfortran -c *.f
R CMD SHLIB -o myLib.so *.o

I'm no UNIX wizard myself, but the way you're trying to do things seems like
the correct way and should work, I have absolutely no idea why it is
complaining about cpu architecture if you have an Intel based machine.

-Charlie


-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University