OS X compiling tips for astronomers & astrophysicists

The following is a bunch of tips I've put together based on experiences compiling some common software/libraries used by astronomers and astrophysicists on Mac OS X. At the moment these tips are limited to Snow Leopard runningin on an Intel core. If you've got tips for another setup, please email them to me.

Legalese: Use these tips at your own discretion. The author/s take no responsibility for and do not guarantee the results of using these tips.

Intel Snow Leopard

General notes: The ranlib/ar/ld combination that snow leopard uses isn't backwards compatible within itself. What I mean by this is that an existing archive can't be appended if it mixes architectures. You will get complaints of `bloated' libraries, etc. and ranlib/ar or the linker will fail. The easiest fix is to use `make clean' to remove all the intermediate files. Sometimes this isn't enough and you'll need to completely remove all traces of the library you're trying to build and start from scratch. Annoying, but effective work-around. Another good tip is to build universal binaries when possible. This will help prevent/resolve a lot of issues. Finally, when you're building a library/tool that makes use of universal binaries, you may get warnings during compilation. These warnings don't necessarily mean the library/tool has failed to build. Use the `make check' or whatever installation verification is available to check the library/tool. If you google 'Urania blog Mac OS X' you will find a treasure trove of tips on compiling astro software on a Mac.

Install order: In my experience, the best order to install the following tools/libraries is the order that I've listed them below.

fortran: The fortran compilers that I use I downloaded from the following website http://hpc.sourceforge.net/ . Installation is very easy and straight forward. Just follow the instructions on their webpage. I have installed all 3 of the fortran compilers available here, gfortran for snowleopard, g77 3.4 and f2c. I've also installed g95 using Macports, but it's largely redundant with gfortran installed (gfortran supersedes g95). If you use Macports it tends to install its own compilers to resolve compatability issues though.

ExtUtils::F77: You can find this perl module on CPAN. Just follow the install instructions on the CPAN webpage. This module allows perl to link to g77/gfortran code, so it's essential if you want to call cfitsio or pgplot from perl.

cfitsio: I set the following variables when running the cfitsio configure script to compile cfitsio. CFLAGS = "-flat_namespace", CPPFLAGS = "-flat_namespace", LDFLAGS = "-Wl,-flat_namespace". drvrgsiftp.c is an empty file on Mac OS X, add 'int ranlib _mac_hack = 1;' to the end of the file to fix the compilation problem during linking. Note that my compiler natively uses '-Dg77Fortran -fPIC -fno-common -c -f -O2', so if you're having problems compiling and you're missing one of these flags, it might be the problem. Make sure that you compile cfitsio as a universal library with the '-arch i386 -arch x86_64' flags. This will help you compile wcslib.

Astro::FITS::CFITSIO: I had to add `use ExtUtils::F77;' to the top of the MakeFile.PL that's included with the Astro::FITS::CFITSIO installation.

pgplot: I had to use the custom sys_macosx file at http://urania.cabanela.com/?s=pgplot and followed the instructions at the bottom of that blog. I noted that my Mac required me to add the following compiler flags '-fno-backslash' for gfortran and '-DPG_PPU' for C. Make sure that you compile pgplot as a universal library with the '-arch i386 -arch x86_64' flags. This will help you compile wcslib.

pgperl: As with pgplot, I followed the instructions at http://urania.cabanela.com/?s=pgplot . The instructions are at the bototm.

wcslib: You should just be able to follow the standard compilation instructions. Make sure to use gfortan and link to the universal libraries for cfitsio and pgplot. I receieved a warning during the linking about the architectures of various libraries not matching, but the included tests all worked properly. At run-time, the universal libraries return the correct architecture. Again, this illustrates the advantage of compiling libraries as universal, dynamic libraries whenever possible.

Miriad: The easiest way to do this is to just grab the binary available from the ATNF computing website. In principle, you should be able to compile it yourself though using the libraries you've built by now.

Duchamp: Just follow the instructions and it should work. Be aware that Duchamp is one of the tools that requires a completely clean installation. If something goes wrong, you'll need to delete everything in the working directory before you try to re-compile/re-install.

kcorrect: kcorrect installs using a `kevilmake' script in the installation's bin directory. I had to tweak the kevilmake script in order to get it to compile. I changed the F77 compiler from g77 to gfortan, which negates the need to use the -lcc_dynamic compiler flag. Delete all mention of -lcc_dynamic in the compiler flags, otherwise you'll get errors and the library won't build. Don't forget to follow the instructions and comment in both sets of lines required to compile the kcorrect C library. Note that I've only confirmed that this will allow me to compile/create the kcorrect C library.

Staff space
Public