Chad R. Bhatti
2009-Apr-15 01:36 UTC
[R] Compiling Fortran Subroutines as R Shared Objects on Mac OS-X
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) I have done this (successfully) before on Sun Solaris and Linux Fedora systems using the following command.> R CMD SHLIB myfile.fI have g77 installed from this page. http://hpc.sourceforge.net/ I am using R 2.8.1, and I have installed all 4 additional packages including gfortran. When I try to compile my subroutines (which worked on two other systems), I get the following error. (I have also tried a very simple subroutine and produced the same error message.) 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 Would anyone happen to understand this error? The words "malformed object" and "cpusubtype" concern me. Note: I am much more of a Unix user than administrator. I have very limited administrator knowledge and vocabulary. I appreciate any help. Many Thanks, Chad R. Bhatti
cls59
2009-Apr-15 18:04 UTC
[R] Compiling Fortran Subroutines as R Shared Objects on Mac OS-X
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.