Building for OS X

To set up your OS X computer for MongoDB development:

Prerequisites

Xcode

Available in the App Store. You only need to get the command line tools, if you don't want to install the whole IDE.

SCons

SCons is the build tool used to compile mongo binaries. It is available from http://www.scons.org.

If you have easy_install or pip already installed, you can use them to install scons.

easy_install scons
pip install scons

git

An installer package is available from http://git-scm.com/

Building

  1. Install any needed prerequisites (see above).
  2. Get the source code
    git clone git://github.com/mongodb/mongo.git
    cd mongo
    
  3. Pick a version to build (only use "master" if you're doing development work).
    1. List all tagged versions
      git tag -l
      
    2. Check out a tagged release, e.g. 2.0.4
      git checkout r2.0.4
  4. Compile
    scons all
  5. Install. Use --prefix to specify where you want to install your binaries. Defaults to /usr/local.
    scons --prefix=/opt/mongo  install

Older Versions of Mongo

Upgrading to Snow Leopard

If you have installed Snow Leopard, the builds will be 64-bit -- so if moving from a previous OS release, a bit more setup may be required than one might first expect.

Setup

Sources

The mongodb source is on github. To get sources first download the git client and install it.

  • Then git clone git://github.com/mongodb/mongo.git (more info)
    Note If you do not wish to install git you can instead get the source code from the Downloads page.

Prerequisites

  • Install gcc. Install XCode tools for Snow Leopard. gcc version 4.0.1 (from older XCode Tools install) works, but you will receive compiler warnings. One way to get a newer gcc is to install Command Line Tools for XCode from developer.apple.com.

Package Manager Setup

  1. Install Homebrew
  2. Update/install dependencies:
    brew install boost
  3. Install SCons:
    brew install scons

Manual Setup

Install Apple developer tools

Install libraries (32-bit option)

  1. Download boost 1.37.0. Apply the following patch:
    diff -u -r a/configure b/configure
    --- a/configure 2009-01-26 14:10:42.000000000 -0500
    +++ b/configure 2009-01-26 10:21:29.000000000 -0500
    @@ -9,9 +9,9 @@
    
     BJAM=""
     TOOLSET=""
    -BJAM_CONFIG=""
    +BJAM_CONFIG="--layout=system"
     BUILD=""
     PREFIX=/usr/local
     EPREFIX=
    diff -u -r a/tools/build/v2/tools/darwin.jam b/tools/build/v2/tools/darwin.jam
    --- a/tools/build/v2/tools/darwin.jam   2009-01-26 14:22:08.000000000 -0500
    +++ b/tools/build/v2/tools/darwin.jam   2009-01-26 10:22:08.000000000 -0500
    @@ -367,5 +367,5 @@
    
     actions link.dll bind LIBRARIES
     {
    -    "$(CONFIG_COMMAND)" -dynamiclib -Wl,-single_module -install_name "$(<:B)$(<:S)" -L"$(LINKPATH)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(FRAMEWORK_PATH) -framework$(_)$(FRAMEWORK:D=:S=) $(OPTIONS) $(USER_OPTIONS)
    +    "$(CONFIG_COMMAND)" -dynamiclib -Wl,-single_module -install_name "/usr/local/lib/$(<:B)$(<:S)" -L"$(LINKPATH)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(FRAMEWORK_PATH) -framework$(_)$(FRAMEWORK:D=:S=) $(OPTIONS) $(USER_OPTIONS)
     }
    

    then,

    ./configure; make; sudo make install
    
  2. Install pcre (must enable UTF8)
    ./configure --enable-utf8 --enable-unicode-properties  --with-match-limit=200000 --with-match-limit-recursion=4000; make; sudo make install
  3. Install c++ unit test framework http://unittest.red-bean.com/ (optional)
    ./configure; make; sudo make install

Install libraries (64-bit option)

(The 64-bit libraries will be installed in /usr/64/{include,lib}.)

  1. Download SpiderMonkey: ftp://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz

Apply the following patch:

diff -u  -r js/src/config/Darwin.mk js-1.7.0/src/config/Darwin.mk
--- js/src/config/Darwin.mk	2007-02-05 11:24:49.000000000 -0500
+++ js-1.7.0/src/config/Darwin.mk	2009-05-11 10:18:37.000000000 -0400
@@ -43,7 +43,7 @@
 # Just ripped from Linux config
 #

-CC = cc
+CC = cc -m64
 CCC = g++
 CFLAGS +=  -Wall -Wno-format
 OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DDARWIN
@@ -56,9 +56,9 @@
 #.c.o:
 #      $(CC) -c -MD $*.d $(CFLAGS) $<

-CPU_ARCH = $(shell uname -m)
+CPU_ARCH = "X86_64"
 ifeq (86,$(findstring 86,$(CPU_ARCH)))
-CPU_ARCH = x86
+CPU_ARCH = x86_64
 OS_CFLAGS+= -DX86_LINUX
 endif
 GFX_ARCH = x
@@ -81,3 +81,14 @@
 # Don't allow Makefile.ref to use libmath
 NO_LIBM = 1

+ifeq ($(CPU_ARCH),x86_64)
+# Use VA_COPY() standard macro on x86-64
+# FIXME: better use it everywhere
+OS_CFLAGS += -DHAVE_VA_COPY -DVA_COPY=va_copy
+endif
+
+ifeq ($(CPU_ARCH),x86_64)
+# We need PIC code for shared libraries
+# FIXME: better patch rules.mk & fdlibm/Makefile*
+OS_CFLAGS += -DPIC -fPIC
+endif

compile and install

cd src
make -f Makefile.ref
sudo JS_DIST=/usr/64 make -f Makefile.ref export

remove the dynamic library

sudo rm /usr/64/lib64/libjs.dylib

# Download boost 1.37.0 Apply the following patch:

diff -u -r a/configure b/configure
--- a/configure 2009-01-26 14:10:42.000000000 -0500
+++ b/configure 2009-01-26 10:21:29.000000000 -0500
@@ -9,9 +9,9 @@

 BJAM=""
 TOOLSET=""
-BJAM_CONFIG=""
+BJAM_CONFIG="architecture=x86 address-model=64 --layout=system"
 BUILD=""
-PREFIX=/usr/local
+PREFIX=/usr/64
 EPREFIX=
 LIBDIR=
 INCLUDEDIR=
diff -u -r a/tools/build/v2/tools/darwin.jam b/tools/build/v2/tools/darwin.jam
--- a/tools/build/v2/tools/darwin.jam   2009-01-26 14:22:08.000000000 -0500
+++ b/tools/build/v2/tools/darwin.jam   2009-01-26 10:22:08.000000000 -0500
@@ -367,5 +367,5 @@

 actions link.dll bind LIBRARIES
 {
-    "$(CONFIG_COMMAND)" -dynamiclib -Wl,-single_module -install_name "$(<:B)$(<:S)" -L"$(LINKPATH)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(FRAMEWORK_PATH) -framework$(_)$(FRAMEWORK:D=:S=) $(OPTIONS) $(USER_OPTIONS)
+    "$(CONFIG_COMMAND)" -dynamiclib -Wl,-single_module -install_name "/usr/64/lib/$(<:B)$(<:S)" -L"$(LINKPATH)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(FRAMEWORK_PATH) -framework$(_)$(FRAMEWORK:D=:S=) $(OPTIONS) $(USER_OPTIONS)
 }

then,

./configure; make; sudo make install

# Install pcre (must enable UTF8)

CFLAGS="-m64" CXXFLAGS="-m64" LDFLAGS="-m64" ./configure --enable-utf8 --with-match-limit=200000 --with-match-limit-recursion=4000 --enable-unicode-properties --prefix /usr/64; make; sudo make install

# Install unit test framework http://unittest.red-bean.com/ (optional)

CFLAGS="-m64" CXXFLAGS="-m64" LDFLAGS="-m64" ./configure --prefix /usr/64; make; sudo make install

Compiling

To compile 32-bit, just run:

scons 

To compile 64-bit on 10.5 (64 is default on 10.6), run:

scons  --64

See the, MongoDB scons page for more details/compile options.

Troubleshooting

  • Undefined symbols: "_PR_NewLock", referenced from: _JS_Init in libjs.a.
    • Try not using the scons --release option (if you are using it). That option attempts to use static libraries.

Follow @mongodb

MongoDB Pittsburgh - May 15
MongoNYC - May 23
MongoDB Paris - Jun 14
MongoDB UK - Jun 20
MongoDC - June 26


Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.

blog comments powered by Disqus