Compile Universal Binary For Mac

Oct 26, 2019 A universal binary is, in Apple parlance, an executable file or application bundle that runs natively on either PowerPC or Intel-manufactured IA-32 or Intel 64-based Macintosh computers; it is an implementation of the concept more generally known as a fat binary. Intel binaries are emulated under Rosetta 2 on Apple Silicon, but there is no emulation of ARM64 on Intel-based mac. But even when you don’t have an Apple Silicon Mac (yet), merely compiling for Universal Binary would be a good start. You’ll know which pre-built 3rd party libraries to update, for which OpenSSL is likely one of several. The whole point of Universal Binaries is that you can compile the same code for 2 architectures, one of which (by necessity) is not the hardware you're running. It has previously been possible to compile Universal Binaries for PPC and Intel, or 32-bit and 64-bit, regardless of the hardware doing the compiling.

Compiling universal binaries. Compiling a universal binary is done by adding -enable-universal to configure:./configure -enable-universal. This is all if your system is set up correctly. Make will then compile for intel, PPC and PPC970 (optimized for this particular CPU. Apple renamed it to G5), so setting G5 flags and such shouldn't be needed.

IMPORTANT: This page has only historical value. It does NOT apply to current R versions. See this page for current information.

NOTE: some links may be broken - older binaries have been lost in an incident.

Mandatory tools

BinaryIn order to compile R for Mac OS X 10.4 or higher, you will need the following tools: (for Mac OS X 10.5 and higher look further down)
  • Xcode Development Tools 2.4.0 (or higher) from Apple
    They can be obtained from Apple's Xcode pages. Also, all recent Mac OS X versions come bundled with Xcode Tools, they are located on the installation DVD. However, if your OS X came with Xcode older than version 2.4.0, you will have to download a more recent version from the above site.

    Note: The binary Leopard build of R on CRAN requires Xcode 3.1 or higher

  • GNU Fortran compiler
    Unfortunately Xcode doesn't contain a Fortran compiler, therefore you will have to install one. For convenience we provide a binary of the GNU Fortran compiler, because most other binaries are either incomplete or broken (do not use compilers from HPC, they won't work correctly!). You can download it from CRAN or here:
    gfortran-4.2.3.dmg (ca. 27MB, GNU Fortran 4.2.3 release)
    MD5 hash: 9551fc46f55537dd1db581154daf27ef

    This binary contains gfortran 4.2.3 (release) for both Intel and PowerPC Macs. It supports all four targets (i386, ppc, x86_64 and ppc64) and features Apple's Darwin compiler drivers, i.e. you can build fat binaries with one command (e.g. gfortran -arch i386 -arch ppc -o tf tf.f).

    Make sure you add /usr/local/bin to your PATH in order to use this compiler. This can be done, e.g. by
    export PATH=$PATH:/usr/local/bin

    Note: If you are interested in cutting-edge compilers and/or integration of GNU Fortran and Apple's compilers see gcc 4.2 section below. That section is also the right place to go if you use the binary Leopard build of R.

    Previous versions:
    gfortran-4.2.1.dmg (ca. 28MB, 4.2.1 release, also avaiable in R 2.6.0)
    gfortran-4.2.0.dmg (ca. 28MB, 4.2.0 release, also avaiable in R 2.5.1)
    gfortran-4.2.0-20070325.dmg (ca. 16MB, 4.2.0 2007/03/25 pre-release without cc back-end)

Mandatory Tools - Leopard CRAN build

R build can be built with the above requirements, but if you want to use source compilation with the CRAN build of R for Mac OS X 10.5 or higher (aka Leopard build), you will need more recent tools:
  • Xcode Development Tools 3.1 (or higher) from Apple with gcc-4.2
    They can be obtained from Apple's Xcode pages. Make sure gcc-4.2 is selected during the installation (default in recent Xcode versions).
  • GNU Fortran compiler
    Do not install Fortran compilers that comde with Tiger builds of R. Remove them using sudo gfortran-uninstall if you installed them before (unless you want to use both builds in parallel). Then install gfortran-4.2 addition to Apple compilers (see below - you have to pick the one that maches your Xcode version!). Although the Tiger compilers supplied with the Tiger build of R can be used, they will result in slightly different binaries.

Optional tools and libraries

The following tools and libraries are optional. R can be compiled without them, but they provide additional capabilities to R.
  • LaTeX
    In order to produce documentation, LaTeX is necessary. It can be obtained from several places, for example as a part of MacTeX.
  • GNU readline
    Although Mac OS X comes with readline-replacement library, it lack some functionality like backward search etc. Therefore many user prefer GNU readline. Binary for all four architectures is provided from CRAN as a part of the devpack: Tools on CRAN or see libs on this site for more recent versions.
  • PNG and JPEG libraries
    If bitmap manipulation libraries are present, R will add graphics device support for those bitmap formats. There are also other package that take advantage of PNG and JPEG, so it is in general a good idea to install them.Again, they are now part of the devpack on CRAN: Tools on CRAN or more recent versions are available from libs.
  • cairo
    R 2.7.0 comes with cairo support. The following tar-ball contains cairo and its dependencies (FreeType, pkgconfig and png) in static form such that you can compile R the same way it is compiled for CRAN:Tools on CRAN

Compile Universal Binary For Mac Pro

Apple Xcode gcc-42 add-ons

  • GNU Fortran 4.2.4 for Mac OS X 10.7 (Lion):
    Download: gfortran-lion-5666-3.pkg (for Xcode 4.1)
    This package adds GNU Fortran to Xcode 4.1 for Lion (Apple's gcc 4.2 build 5666.3). Requires Mac OS X 10.7 (Lion) and Xcode 4.1.

    gcc-4.2 (Apple build 5666.3) with GNU Fortran 4.2.4 for Mac OS X 10.7 (Lion):
    Download: gcc-42-5666.3-darwin11.pkg (for Xcode 4.2 and higher)
    This package contains gcc-4.2 (Apple build 5666.3) including GNU Fortran for Mac OS X 10.7 (Lion). It is needed for Xcode 4.2 or higher since Apple has dropped gcc-4.2 from Xcode. It works with Xcode 4.0 and 4.1 as well, but there you can use the above smaller Fortran package instead.

  • GNU Fortran 4.2.4 for Mac OS X 10.6 (Snow Leopard):
    Download: gfortran-42-5664.pkg (for Xcode 3.2.3 through 3.2.5)
    This package adds GNU Fortran to Xcode 3.2.3/4/5 for Snow Leopard (Apple's gcc 4.2 build 5664). Requires Mac OS X 10.6 (Snow Leopard) and Xcode 3.2.3, 3.2.4 or 3.2.5 (it will also work with more recent Xcode such as 4.0 or 4.1 on Snow Leopard since Apple stopped updating gcc)
    Download: gfortran-42-5659.pkg (for Xcode 3.2.2)
    This package adds GNU Fortran to Xcode 3.2.2 for Snow Leopard (Apple's gcc 4.2 build 5659). Requires Mac OS X 10.6 (Snow Leopard) and Xcode 3.2.2.
    Download: gfortran-42-5646.pkg (for Xcode 3.2 and 3.2.1)
    This package adds GNU Fortran to Xcode 3.2 for Snow Leopard (Apple's gcc 4.2 build 5646). Requires Mac OS X 10.6 (Snow Leopard) and Xcode 3.2 (or 3.2.1).

    Dynamic libgfortran: libgfortran-4.2.4-5646.tar.gz (NOT needed for R)
    The compiler above contains static libgfortran. To avoid library pollution the dynamic gfortran library is not included since it is not necessary for most projects and causes problems for people that don't have it installed at run-time. If you know what you're doing, you can install it, but be aware that your FORTRAN binaries will depend on it and OS X does NOT include it.
    Install: sudo tar fxz libgfortran-4.2.4-5646.tar.gz -C /

  • GNU Fortran 4.2.4 for Mac OS X 10.5 (Leopard):
    Download: gfortran-42-5577.pkg (for Xcode 3.1.4 only!)
    This package adds GNU Fortran 4.2.4 to Apple's Xcode 3.1.4 gcc 4.2 (build 5577) compilers on Mac OS X 10.5 (Leopard). It does NOT work on Snow Leopard. This binary has been built the Apple way with the gcc_42 (build 5577) sources (by adding the Fortran directories from gcc 4.2.4 release), so it features full Apple driver (i.e. all special flags work) and works directly with the gcc 4.2 system compiler. You have to install Xcode 3.1.4 first (from ADC).

    Older versions:
    GNU Fortran 4.2.4 for Apple's gcc-4.2 (build 5564) = Xcode 3.1 and 3.1.1:
    gfortran-4.2-5564-darwin9.tar.gz
    GNU Fortran 4.2.4 for Apple's gcc-4.2 (build 5566) = Xcode 3.1.2:
    gfortran-4.2-5566-darwin9.tar.gz
    GNU Fortran 4.2.4 for Apple's gcc-4.2 (build 5577) = Xcode 3.1.4:
    gfortran-4.2-5577-darwin9.tar.gz (same as the above installer)
    Installation: sudo tar fvxz gcc-4.2-5577-darwin9-all.tar.gz -C /

  • gcc 4.2 (Apple Inc. build 5566) for Mac OS X 10.4 (Tiger): (updated 2008/12/24)
    Download: gcc-4.2-5566-darwin8-all.tar.gz (Apple gcc 4.2 build 5566 [as in Xcode 3.1.2] + GNU Fortran 4.2.4)
    The above tar-ball contains compilers, docs and 10.4u SDK - unpack using:
    sudo tar fvxz gcc-4.2-5566-darwin8-all.tar.gz -C /
    The above compilers don't replace existing 4.0 or older compilers, use as gcc-4.2, g++-4.2 etc. or create symlinks if you want to make it the default compiler (or use sudo gcc_select 4.2).
    (Note: SDK and documentation is assumed to live in /Developer - move accordingly for non-standard installations).

Previous (older) versions

  • gcc 4.2 (Apple Inc. build 5553) for Mac OS X 10.4 (Tiger):
    Download: gcc-42-5553-darwin8-all.tar.gz (Apple gcc 4.2 build 5553 + GNU Fortran 4.2.3)
    The above tar-ball contains compilers, docs and 10.4u SDK - unpack using:
    sudo tar fvxz gcc-42-5553-darwin8-all.tar.gz -C /
    The above compilers don't replace existing 4.0 or older compilers, use as gcc-4.2, g++-4.2 etc. or create symlinks if you want to make it the default compiler.
  • gcc 4.2 (Apple Inc. build 5531) for Mac OS X 10.4 (Tiger) (older than above):
    Download: gcc-42-5531-darwin8.tar.gz (Apple gcc 4.2 build 5531)
    Download: gcc-42-5531-darwin8-SDK.tar.gz (MacOSX10.4u SDK files)
    Download: gfortran-42-5531-darwin8.tar.gz (GNU Fortran)
    This is a set of Apple's gcc 4.2.1 (build 5531) compilers for Mac OS X 10.4 (Tiger). Xcode 2.5 has gcc 4.0 only, and gcc 4.2 update is currently available only for Leopard, so this binary fills the gap.
    The second file contains the Fortran compiler which is not part of the Apple sources, but was compiled along with the Apple sources.

Building a universal compiler

Note: This section is now becoming obsolete given Apple's gcc 42 branch, but it is kept here until we have more definite information on Apple's Fortran support. If you're interested in compiling Apple's gcc-4.2 branch with Fortran support, add Fortran sources and use this patch: gfortran-5564.diff (for gcc-4.2 Apple build 5564/5566/5577 and GNU Fortran 4.2.4) or gfortran-5531.diff (for gcc-4.2 Apple builds 5531 or 5553 and GNU Fortran 4.2.3). Complete sources are also in /src.

Apple provides universal compilers in their Xcode tools. This means that the compiler itself can be run on both on Intel and PowerPC Macs natively. In addition, Apple's compilers can produce binaries for any of the architectures i386, ppc, x86_64 and ppc64. This mean that the same compiler suite is usable on any Mac and can target any Mac as well.

Apple also provides a special driver for all compilers such that they support additional flags such as -arch which allow us to build fat binaries in one run. Internally the driver invokes multple separate compilers, one for each distincts -arch flag and combines the result using lipo. This is highly convenient and allows for compilation of the form:
gcc -c foo.c -arch ppc -arch i386 -arch ppc64 -arch x86_64
which produces one fat object file (foo.o) containing binaries for all four architectures.

Unfortunately Apple's branch of gcc is based on a fairly old version of gcc and they don't support Fortran. (Update: 2007/11 there is some hope, Apple's gcc-42 branch can be used to compile Fortran - see binaries above - and Apple is allegedly working on an official Fortran release) Therefore it is sometimes necessary to compile gcc from the original FSF sources. However, such compilers (e.g. as provided by HPC) are very limited, because they work only on one kind of Mac (Intel or PPC) and don't support cross-compiling. Therefore is it necessary to merge Apple's approach and FSF gcc sources to create a more usable compiler for Mac OS X.

In this part I want to describe steps necessary to create such universal compiler from any gcc sources. The whole process is fully automated by a shell script which can be obtained here (it must be run sudo unless you have write-premissions in /usr/local). I have used this procedure to create the Fortran compiler available above. Run the script with '-h' flag to see all the options.

How does it work?

Compile Universal Binary For Mac Os

Conceptually Apple's drivers use naming scheme to distinguish compilers for Intel and PowerPC targets. In the Xcode installation they are called powerpc-apple-darwin8-gcc-4.0.1 and i686-apple-darwin8-gcc-4.0.1. The virtual targets ppc64 and x86_64 are compiled by adding -m64

Compile Universal Binary For Mac Free

flags to the corresponding compiler. The driver (gcc-4.0

Mac Universal Binary

) invokes the actual compiler(s) that are needed and uses lipo to create the resulting fat object/binary.

In order to build an universal compiler suite, we need to proceed using these steps:

  • get cross-compilation tools
    The building process requires tools for cross-compilation to be of the form <arch>-apple-darwin8-<tool>. However, Apple's tools expect the -arch flag instead of naming conventions. Therefore it is necessary to create small stubs that map FSF naming conventions into corresponding invocations of the Apple tools. Such stubs are automatically generated by Apple's gcc bulding process, but they are also available in this file: gcc-bin-stubs.tar.gz
  • get gcc sources
    This is obviuos, you clearly need gcc sources. One way to get them is via svn, for example:
    svn co svn://gcc.gnu.org/svn/gcc/branches/gcc-4_2-branch gcc-4.2
  • compile and install the native compilers
    The compilation part is straight-forward, just configure and build gcc for the i686-apple-darwin8 host and powerpc-apple-darwin8 host. The harder part is the installation, because Apple uses fat files, whereas FSF's multilibs relies on different names. First install one architecture, rename the binaries according to Apple's compiler name conventions and move everything in /usr/local/lib aside. Then install the other architecture and do the same. Finally combine all system libraries using lipo into /usr/local/lib. This applies also to 64-bit architectures which should also be included in the libraries placed in /usr/local/lib. Then get all the other files and symlinks back. Finally remove everything from the subdirectories in lib and replace it with symlinks. This should give you a working environment for all four targets. Finally adjust the IDs of the libraries to match their location.
  • compile and merge cross-compilers
    With the above compiler we cannot create universal binaries, because the cross-compilers are missing. We need to compile them now. Note that we don't need libraries anymore, because they are already in place, so even if some of the libraries fail when cross-compiled, we don't care. The cross-compilers don't even need to be installed, just lipo the binaries of the cross-compilers into /usr/local/libexec/gcc/*-apple-darwin*/* and the drivers into /usr/local/bin with the corresponding name. You may want to strip them as well in order to reduce size.
  • get and install the Darwin driver
    The driver is part of Apple's gcc and can be obtained correspondingly. I have packaged the minimal sources and the corresponding Makefile into one small tar-ball which is available here: gcc-darwin-driver.tar.gz. It is based on gcc-5363 sources released by Apple, but the Makefile allows the use of any Apple's gcc sources - just set AGCC accordingly. Move the resulting driver files into /usr/local/bin and you're all set!
Was this too compilcated? Well, use the script above or just fetch the binaries which are provided in the form of a convenient Apple installer above.(sources for open source software not linked directly)

Compile Universal Binary For Mac Windows 7

Disclaimer

Compile Universal Binary For Machine Learning

All software is provided 'as is' and any express or implied warranties, including, but but not limited to the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall AT&T, the publisher, copyright owner or contributors be liable for any direct, indirect, incidental,special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.