Edit page History How do I edit this website?

Building Universal Binaries on Mac OS X

See [[Build on MacOS X]] for up-to-date instructions on building on OS X. If you really need to build universal binaries, look at the scripts in buildscripts/nightly/nightlybuild_OSX_*.sh for how to do it. It is no longer necessary to build for separate architectures and merge the binaries afterwards.

We found the least painful way to build Universal Binaries (32-bit ppc, 32-bit intel, 64-bit intel) to be to build code for each platform individually and then use the lipo tool to combine these libraries into Universal Binaries. The Micro-Manager repository contains scripts that will execute cross-compilation for the three platforms (see nightlyBuildMMac.sh and buildMMMac.sh), however, the supporting libraries (currently, boost, libdc1394, libusb, and for 1.4 also libtiff and zlib) need to be build for each platform independently. Below are some notes on how this can be accomplished:

Cross-compiling Boost for three platforms:

sudo ./bjam --install --build-dir=ppc --toolset=darwin --link=static --runtime-link=static --threading=multi --layout=tagged --prefix=/usr/local/ppc architecture=power address-model=32 macosx-version-min=10.4 --with-system --with-thread --with-iostreams --with-date_time --libdir=/usr/local/ppc/lib --includedir=/usr/local/ppc/include --stagedir=/usr/local/ppc
sudo ./bjam --install --build-dir=i386 --toolset=darwin --link=static --runtime-link=static --threading=multi --layout=tagged --prefix=/usr/local/i386 architecture=x86 address-model=32 macosx-version-min=10.4 --with-system --with-thread --with-iostreams --with-date_time --libdir=/usr/local/i386/lib --includedir=/usr/local/i386/include --stagedir=/usr/local/i386
sudo ./bjam --install --build-dir=x86_64 --toolset=darwin-4.2 --link=static --runtime-link=static --threading=multi --layout=tagged --prefix=/usr/local/x86_64 architecture=x86 address-model=64 macosx-version-min=10.5 --with-system --with-thread --with-iostreams --with-date_time --libdir=/usr/local/x86_64/lib --includedir=/usr/local/x86_64/include --stagedir=/usr/local/x86_64

Cross-compiling libtiff for three platforms:

./configure --prefix=/usr/local/i386 CC="gcc-4.0" CFLAGS="-g -O2 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386" CXXFLAGS="-g -O2 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386" CXX="g++-4.0"
make clean
make
sudo make install
./configure --prefix=/usr/local/ppc CC="gcc-4.0" CFLAGS="-g -O2 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc" CXXFLAGS="-g -O2 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc" CXX="g++-4.0"
make clean
make
sudo make install
./configure --prefix=/usr/local/x86_64 CC="gcc-4.2" CFLAGS="-g -O2 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch x86_64" CXXFLAGS="-g -O2 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch x86_64" CXX="g++-4.2"
make clean
make
sudo make install

Cross-compiling zlib for three platforms:

export CC="gcc-4.0"
export CFLAGS="-g -O2 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386"
export CXX="g++-4.0"
export CXXFLAGS="-g -O2 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386"
./configure --prefix=/usr/local/i386
make clean
make
sudo make install
export CC="gcc-4.0"
export CFLAGS="-g -O2 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc"
export CXX="g++-4.0"
export CXXFLAGS="-g -O2 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc"
./configure --prefix=/usr/local/ppc
make clean
make
sudo make install
export CC="gcc-4.2"
export CFLAGS="-g -O2 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch x86_64"
export CXX="g++-4.2"
export CXXFLAGS="-g -O2 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch x86_64"
./configure --prefix=/usr/local/x86_64
make clean
make
sudo make install

Cross compiling gphoto2 for three platforms:
This worked with libgphoto 2.4.11. Older versions had problems in some of the camera drivers and would need these to be excluded from the build.

make clean  
./configure --prefix=/usr/local/ppc CC="gcc-4.0" CFLAGS="-g -O2
-mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk
-arch ppc" CXXFLAGS="-g -O2 -mmacosx-version-min=10.4 -isysroot
/Developer/SDKs/MacOSX10.4u.sdk -arch ppc" CXX="g++-4.0" --enable-static
--host=ppc-darwin --with-libexif=no --without-libiconv-prefix
--without-libintl-prefix LIBLTDL=/usr/local/ppc/libltdl.a
LIBUSB\_LIBS="/usr/local/ppc/lib/libusb.a -framework IOKit -framework
CoreFoundation" LIBUSB\_CFLAGS=-I/usr/local/ppc/include
LIBLTDL=/usr/local/ppc/lib/libltdl.a
PKG\_CONFIG\_LIBDIR="/usr/local/ppc/lib/pkgconfig/"  
make  
sudo make install  
make clean  
./configure --prefix=/usr/local/x86\_64 CC="gcc-4.2" CFLAGS="-g -O2
-mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch
x86\_64" CXXFLAGS="-g -O2 -mmacosx-version-min=10.5 -isysroot
/Developer/SDKs/MacOSX10.5.sdk -arch x86\_64" CXX="g++-4.2"
--enable-static --with-libexif=no --without-libiconv-prefix
--without-libintl-prefix LIBUSB\_LIBS="/usr/local/x86\_64/lib/libusb.a
-framework IOKit -framework CoreFoundation"
LIBLTDL=/usr/local/x86\_64/lib/libltdl.a
LIBUSB\_CFLAGS=-I/usr/local/x86\_64/include
PKG\_CONFIG\_LIBDIR="/usr/local/x86\_64/lib/pkgconfig/"  
make clean  
make  
sudo make install  
./configure --prefix=/usr/local/i386 CC="gcc-4.0" CFLAGS="-g -O2
-mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk
-arch i386" CXXFLAGS="-g -O2 -mmacosx-version-min=10.4 -isysroot
/Developer/SDKs/MacOSX10.4u.sdk -arch i386" CXX="g++-4.0"
--enable-static --with-libexif=no --without-libiconv-prefix
--without-libintl-prefix LIBUSB\_LIBS="/usr/local/i386/lib/libusb.a
-framework IOKit -framework CoreFoundation"
LIBUSB\_CFLAGS=-I/usr/local/i386/include
LIBLTDL=/usr/local/i386/lib/libltdl.a
PKG\_CONFIG\_LIBDIR="/usr/local/i386/lib/pkgconfig/"  
make  
sudo make install  

Cross-compiling libbzip2 (useful for OpenCV) for three platforms: Download the source from bzip.org
Edit the Make file:

CC=gcc-4.0  
CFLAGS=-g -O2 -mmacosx-version-min=10.4 -isysroot
/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -Wall -Winline $(BIGFILES)  
make  
sudo make install PREFIX=/usr/local/i386  
make clean  

Edit the Make file for x86_64:

CC=gcc-4.2  
CFLAGS=-g -O2 -mmacosx-version-min=10.5 -isysroot
/Developer/SDKs/MacOSX10.5.sdk -arch x86\_64 -Wall -Winline
$(BIGFILES)  
make  
sudo make install PREFIX=/usr/local/x86\_64  
make clean  

Building OpenCV: General instructions can be found on the openCV site.
In a freshly downloaded OpenCV source, run:

mkdir buildi386  
cd buildi386  
CC=gcc-4.0 CXX=g++-4.0 cmake -DCMAKE\_BUILD\_TYPE=RELEASE
-DCMAKE\_INSTALL\_PREFIX=/usr/local/i386 -DBUILD\_SHARED\_LIBS=OFF
-DBUILD\_TESTS=OFF -DBZIP2\_LIBRARIES=/usr/local/i386/libbzip2.a
-DWITH\_OPENCL=OFF -DBUILD\_NEW\_PYTHON\_SUPPORT=OFF -DWITH\_JASPER=OFF
-DWITH\_JPEG=OFF -DWITH\_PNG=OFF -DWITH\_TIFF=OFF -DWITH\_OPENEXR=OFF
-DCMAKE\_OSX\_ARCHITECTURES=i386 -G "Unix Makefiles" ..  
make  
sudo make install  
cd ..  
mkdir buildx86\_64  
cd buildx86\_64  
cmake -DCMAKE\_BUILD\_TYPE=RELEASE
-DCMAKE\_INSTALL\_PREFIX=/usr/local/x86\_64 -DBUILD\_SHARED\_LIBS=OFF
-DBUILD\_TESTS=OFF -DWITH\_OPENCL=OFF -DBUILD\_NEW\_PYTHON\_SUPPORT=OFF
-DCMAKE\_OSX\_ARCHITECTURES=x86\_64 -DWITH\_JASPER=OFF -DWITH\_JPEG=OFF
-DWITH\_PNG=OFF -DWITH\_TIFF=OFF -DWITH\_OPENEXR=OFF -G "Unix Makefiles"
..  
make  
sudo make install