R for Mac OS X Developer's Page - Building R
This page contains details that didn't make it to the FAQ or are too recent to make it to the release.
R on Mac OS X 10.5 (Leopard)
First, a general note: Leopard users should use an update from CRAN in order to install R. Leopard has issues with the installer of previous versions of R (including R 2.6.0 release which was released before Leopard was available).
Now for the development part.
Fixing X11 on Leopard
X11 is broken on Leopard (still as of 10.5.2 release), it is impossible to compile programs against it (more precisely whenever libGL is touched - directly or indirectly). The easiest way to fix it is as follows:
cd /usr/X11/lib
sudo bash
# enter your password
mv libGL.dylib libGL.dylib.apple
ln -s /System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib .
Compiling R
Due to a bug in /bin/sh it is necessary to specify another, compliant shell. SHELL=/bin/ksh and SHELL='/bin/bash' are known to work (when passed to configure). (R-devel and R 2.6.2 provide a work-around)
Also note that the default locale in Terminal is now UTF-8 (see its Preferences), which triggers bugs in tools like sed, so it is highly recommended to use the C locale instead (either by changing the preferences or setting LANG to C).
Bulidng of R itself does not require any special flags (other than the above). A simple configure && make && make install is known to work. However, for a proper 64-bit support, read on.
Apple gcc 4.2
If you have access to Apple's gcc 4.2 compilers (they are public now), you may want to use them instead.
We have compiled a GNU Fortran specifically for Apple's gcc 4.2 that simply adds Fortran capability to the system compilers. Get it from the tools page (Alternative tools section further down the page) instead of the Fortran that comes with R.
Universal 32- and 64-bit
Leopard supports 64-bit throughout, including in the R GUI. However, support for 64-bit Quartz was added in R-devel, it is by default not incuded in R 2.6.0. In order to compile 64-bit R, you have to use most recent R 2.6 patched version or R-devel. Then use compiler flags to specify the target architecture as well as r_arch to tag it. For example:
r_arch=x86_64 \
CC="gcc -arch x86_64 -std=gnu99" \
CXX="g++ -arch x86_64" \
OBJC="gcc -arch x86_64" \
F77="gfortran -arch x86_64" \
FC="gfortran -arch x86_64"
Replace x86_64 with i386, ppc or ppc64 to build the other architectures. Each make install will merge the current architecture with the others. On an Intel-based Mac, it is possible to build all but the ppc64 architecture.
Copy/paste guide
The is just an easy way to get started with R on a Leopard Intel-based machine. Make sure you have installed Xcode 3.0 and GNU Fortran from the tools page first. The script below assumes bash-like shell.
PATH=/usr/X11/bin:/usr/local/bin:$PATH
export PATH
LANG=C
export LANG
svn co https://svn.r-project.org/R/trunk R-devel
# you may have to accept a certificate here
cd R-devel
tools/rsync-recommended
cd ..
# got the sources, on to building 64-bit R
mkdir rd64
cd rd64
../R-devel/configure SHELL='/bin/bash' \
r_arch=x86_64 \
CC="gcc -arch x86_64 -std=gnu99" \
CXX="g++ -arch x86_64" \
OBJC="gcc -arch x86_64" \
F77="gfortran -arch x86_64" \
FC="gfortran -arch x86_64" \
--with-system-zlib \
--with-blas='-framework vecLib' --with-lapack && \
make -j4 && \
make check && \
make install
cd ..
# if you want a 32-bit build as well, continue here
mkdir rd32
cd rd32
../R-devel/configure SHELL='/bin/bash' \
r_arch=i386 \
CC="gcc-4.0 -arch i386 -std=gnu99" \
CXX="g++-4.0 -arch i386" \
OBJC="gcc-4.0 -arch i386" \
F77="gfortran-4.0 -arch i386" \
FC="gfortran-4.0 -arch i386" \
--with-system-zlib \
--with-blas='-framework vecLib' --with-lapack && \
make -j4 && \
make check && \
make install
cd ..
# done - you should have 32-bit and 64-bit R
# set r_arch on the command line to start the corresponding R