Need native supports for Fortran !
By dong_li_1985 at Fri, May 15 2009 9:11am |
Hi, all,
I am looking for a convenient way to compile Fortran codes in Mac OS X for a long time, especially with Xcode. What I need is an environment to maintain my codes and easy to compile and debug them. Could Xcode provide native supports for Fortran? I believe many people will gain benefit from them.
DONG Li




Comments
Hi Dong Li: I too share your
Hi Dong Li:
I too share your frustration, and only recently got a fairly messy legacy Fortran code to link with some C-routine wrappers into a dynamic library. I tried several things, and ultimately used the gfortran-snwleo-intel-bin.tar that I downloaded from HPC: http://hpc.sourceforge.net/
My problem, and I think it is fairly common, is that I wasn't clear on the process and thus read lots of conflicting information and then ended up putting code in places that conflicted with each other. Here's my mental model of what to do, based on my requirements: (1) I wanted to get the Fortran to create 64-bit code to be compatible with compiled C-code using Xcode, which is default 64 bit on Snow Leopard; (2) I wanted the build process to operate within Xcode, and not have to do command line work only on Fortran source; and (3) my Fortran use was one of necessity for linking in work done by others, whereas I would be writing only C wrappers for using it in other C programs or as a library running under Matlab.
If you already stuffed various flavors of Fortran around in your directory, do what you can to clean that up. I spent way too much time trying to get the ATT gfortran (supplied with the code for building the R package) to work, since it had a Mac GUI installer and claimed to do the interface into Xcode. I'm pretty sure that might have worked, but the system I had when I did that install had too much extraneous stuff littered about to let the compiler/linker find what it needed to. Ultimately, I used Finder to locate all the gfortran command files, and the libgfortran* libraries, and quite simply, deleted them. You can do this from the command line, but using Finder and the find command was just as easy.
Then, reading the info at the HPC Mac site, I downloaded and installed the gfortran-only binary provided for Snow Leopard. A trip to the command line, and I got a simple program to compile and link. It included some math expressions as well, as these (exponents) seemed to trip up my previous install attempts. Off to Xcode, I then modified the descriptors for doing Fortran compiles, as per the instructions I found while digging here at MacResearch. What I did was:
(1) Start up Xcode (you DID install it didn't you?) and create a C Dynamic Library project
(2) Grab appropriate Fortran and C files and add to the project
(3) Click on the target, and then pick "info" (clover-I), and under the "General" tab add the libgfortran.3.dylib by using the + key in the lower left corner, then browsing to /usr/local/lib to find it
(4) Click on the Rules tab in the same Info window, and click the plus in the bottom left corner to add a new rule, then:
(4a) select "Fortran source files" from Process:
(4b) select "Custom script:" from using:
(4c) enter the following to point to the gfortran incantation:
/usr/local/bin/gfortran -g -m64 -fno-underscoring -c ${INPUT_FILE_PATH} -o ${TARGET_BUILD_DIR}/${INPUT_FILE_BASE}.o
(4d) enter the following in the box below the two lines reading "with output files:" "Name":
$(TARGET_BUILD_DIR)/$(INPUT_FILE_BASE).o
My understanding is that the Script you just created tells Xcode what to do with Fortran files, but just for that product at hand. This is not a universal Script for Xcode to use forever, just this time while you build this specific project. You'll have to re-enter the script for other Xcode projects using Fortran.
That, to my recollection, was what I needed to make things work. I may have tweaked some of the Build settings shown in the same Target info window, but I can't remember. At any rate, a process that started maybe in November of 2009 is, at last, finally completed.
I sincerely hope that helps, and I hope that others augment those comments that are extraneous or downright wrong. Good luck, and hang in there.
-B.
Bob McKillip