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

cls59 sharpsteen at mac.com
Wed Apr 15 20:04:17 CEST 2009




Chad R. Bhatti wrote:
> 
> 
> Hello,
> 
> I am trying to compile some F77 subroutines as shared objects for R on my
> Mac.
> --> Mac OS-X Version 10.4.11 (Tiger Intel Mac)
> 
> <SNIP>
> 
> chad-r-bhattis-computer:~/MyR/Examples/Fortran/Test1 chadrbhatti$ R CMD
> SHLIB two.f
> gfortran -arch i386   -fPIC  -g -O2 -c two.f -o two.o
> gcc -arch i386 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names
> -mmacosx-version-min=10.4 -undefined dynamic_lookup -single_module
> -multiply_defined suppress -L/usr/local/lib -o two.so two.o  -lgfortran
> -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
> -Wl,CoreFoundation
> /usr/bin/libtool: for architecture cputype (16777223) cpusubtype (3)
> object: /usr/local/lib/libgfortran.dylib malformed object (unknown load
> command 4)
> /usr/bin/libtool: for architecture cputype (16777223) cpusubtype (3)
> object: /usr/local/lib/libgcc_s.10.4.dylib malformed object (unknown load
> command 4)
> make: *** [two.so] Error 1
> chad-r-bhattis-computer:~/MyR/Examples/Fortran/Test1 chadrbhatti$ which
> g77
> /usr/local/bin/g77
> chad-r-bhattis-computer:~/MyR/Examples/Fortran/Test1 chadrbhatti$ which
> gfortran/usr/local/bin/gfortran
> 
> 

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
-- 
View this message in context: http://www.nabble.com/Compiling-Fortran-Subroutines-as-R-Shared-Objects-on-Mac-OS-X-tp23051543p23064039.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list