[Rd] call fortran in R
Bill Northcott
w.northcott at unsw.edu.au
Fri Aug 5 09:56:46 CEST 2005
On 04/08/2005, at 8:00 PM, Sebastien Durand wrote:
> I used a mac G5, R.2.1.1, and G77 3.4.4 and I would like to use and
> call a fortran subroutine.
> The trouble is that it seems I am not able to correctly load the
> compiled code.
.................
> base
> 2 /Library/Frameworks/R.framework/Resources/library/grDevices/libs/
> grDevices.so
> 3 /Library/Frameworks/R.framework/Resources/library/stats/
> libs/stats.so
> 4 /Library/Frameworks/R.framework/Resources/library/methods/libs/
> methods.so
> 5 /Users/sebas/Desktop/Fortan_kmeans/kmeans3.so
>
> Dynamic.Lookup
> 1 FALSE
> 2 FALSE
> 3 FALSE
> 4 FALSE
> 5 TRUE
I really wish someone would make these issues clear in MacOS R
documentation.
MacOS X 10.3 Panther uses gcc-3.3 as its default compiler. The R
binary is built with gcc-3.3 and g77 3.4 so that it will run on Panther.
MacOS X 10.4 Tiger uses gcc-4.00 as its default compiler. This
causes two problems.
1. Fortran objects built with g77 cannot be linked with C/C++
objects built with gcc-4.0. So an R package with a mixture of C and
Fortran code will very likely fail at some point.
2. Even if you specifically invoke gcc-3.3 and g77 the code will
still fail to link because it needs a symlink /usr/lib/
libcc_dynamic.dylib which points to libgcc.a. This link is missing
if the default gcc-4.0 is the selected compiler. (It is missing
because it does not work with gcc-4).
If you want to build Fortran source packages on Tiger using the R
binary distribution, you need to to do
'sudo gcc_select 3.3'
That command will make gcc-3.3 the default compiler and reinstate the
symlink, which recreates the environment in which the R binary was
built. You can always go back to gcc-4.0 with 'sudo gcc_select 4.0'.
Bill Northcott
More information about the R-devel
mailing list