The easiest way to install gfortran is by using a binary installation. The binary installation can be found at the following site: http://gcc.gnu.org/wiki/GFortranBinaries
The above website currently provides four different binary installation options.
- Fink - A package manager for Mac OS X that aims to port a lot of GNU software to the Mac operating system for easy installation.
- HPC - High Performance Computing. Offers relatively up to date binary installations for both Mac OS X 10.5 and 10.6.
- r.research.att.com - Offers a binary installation, but only for an older version of gfortran/gcc.
- gcc.gnu.org - Provides an Apple-style installer for certain versions of gfortran.
I have tried installing gfortran/gcc using Fink, however, I had mixed results. Fink made my computer run quite hot and took much longer than other binary sources. Unfortunately, the gfortran/gcc version provided by r.research.att.net is an older release, so it probably won't have access to the newer features added to gfortra. I have not tried the "Apple like installer" option provided by gnu.gcc.org, as they have just recently begun to provide binaries for Mac OS X 10.6. I have found that using the binary installation provided by HPC is the most straightforward and up to date way to install gfortran on Mac OS X. Currently a development edition of gfortran 4.6 is provided. The direct link to their website is here: http://hpc.sourceforge.net/.
Install Apple Developer Tools
Before installing gfortran, it is required that the Apple Developer Tools (which includes Xcode) be installed. The developer tools can be installed from the operating system installation disc or they can be installed by downloading a .dmg from Apple’s website which requires a free registration and login to access: http://developer.apple.com/technologies/xcode.html
gfortran Binary Installation
I have chosen to provide instructions using the HPC binary installation. There are install instructions on the HPC website (http://hpc.sourceforge.net/), but I will also include the installation instructions here. To begin, select the .dmg from the HPC website that corresponds to the Mac operating system you are using (either 10.5 or 10.6). For example, I downloaded the file gfortran-snwleo-intel.bin.tar.gz since I am running Mac OS X 10.6, aka Snow Leopard. Once the .dmg has been downloaded, open a Terminal window and "cd" to the folder where the file was saved. For example, if I saved the file in my Downloads folder, I would use the following Terminal commands:
$ cd /users/user/downloads
Once at the location of the .dmg file, type the following into the Terminal command prompt:
$ gunzip gfortran-snwleo-intel-bin.tar.gz $ sudo tar -xvf gfortran-snwleo-intel-bin.tar.gz -C /
Note that the "sudo" command requires you to enter the administrator password. That's it. The above process performs a binary installation of gfortran in the hidden directory /usr/local. It should be noted that this folder will only exist after the Apple Developer Tools have been installed. One method used to view this directory in Finder is to issue the following command in Terminal:
$ open -a finder /usr/local
If the folder does not exist, install the Developer Tools! I am not sure, but I believe the gfortran install process would have failed if the Developer Tools were not installed properly at this time.
Modify PATH
It is possible that gfortran is ready to use at this time. However, there is also the possibility that the /usr/local/bin folder (where the gfortran executable is stored) still needs to be added to the PATH. This allows the executable to be invoked while in any folder in Terminal. I believe by default the folder is in the path on 10.6, but it is possible that something has been changed. To manually add the folder to the PATH, we will open a text editor in Terminal and edit the file /etc/paths.
$ sudo pico /etc/paths
Opening this file requires entering the admin password. If the file /etc/paths contains a line /usr/local/bin, the file can be closed with CTRL+X. If not present, arrow down to the last available line and type the folder location:
/usr/local/bin
After the folder has been added, CTRL+X, press Y to save the file, and then press enter to exit the file. Terminal needs to be closed and re-opened before the changes take effect.
Test Installation
To test if gfortran is installed and the PATH is defined correctly, type the following in Terminal:
$ gfortran
gfortran: no input files
Seeing the above result indicates that the gfortran executable was found via the PATH, was executed, and correctly issued the error message indicating there was no Fortran source file specified on the command line. It is entirely possible that while the gfortran executable will work with no input files, when it comes time to compile a file, the executable might fail if not installed properly. To test gfortran with a Fortran source input file, see the previous post titled "Hello!" which contains the source code and steps required to compile, link, and run the created executable.
The disadvantage of installing a binary gfortran executable is that you are at the mercy of the binary creator/maintainer to keep the binary up to date. I recently ran into a problem where a bug in gfortran was fixed, but the binary file was not up to date with the fix. Therefore, the next best option is to install gfortran from source code. This takes a little longer and is a little more complicated, but it will allow you to test the working development of gfortran or a version that the binary supplier does not support. That is next on the list to be added here.
I will also try to add posts that outline how to install gfortran on Ubuntu and Windows sometime.
No comments:
Post a Comment