Building MongoDB with clang and libc++

I am working in a project that I use MongoDB as data storage system. I really like to “trunk” version, directly from git [https://github.com/mongodb/mongo]. Even using a Mac, I used to compile MongoDB with gcc. Because MongoDB had a problem with the clang suite. Today I realized that it was fixed: https://jira.mongodb.org/browse/SERVER-8467.

In the same way, since I updated to Maverick, I had small problems builind my project. Mainly problem in the linking phase, where for some reason it was linking the binaries with libc++ where it was expected to link it with libc++ (because MongoDB and Boost were built using libc++).

So, after some time, I compiled the BOOST libraries, MongoDB, and my project using  clang/clang++ and libc++.

I will explain here the steps, if you want to know why I used some parameter or other, please ask at the comments.

For it, I did:

mkdir /opt/boost-clang-libc++/ 
mkdir /opt/mongo-clang-libc++/ 

Downloaded Boost libraries from http://sourceforge.net/projects/boost/files/boost/1.54.0/
U
ncompressed,  and inside the directory I did:

./bootstrap.sh  --prefix=/opt/boost-clang-libc++/
./b2 variant=debug link=static threading=multi toolset=clang cxxflags="-stdlib=libc++ -arch x86_64" linkflags="-stdlib=libc++” --with-system --with-thread --with-date_time --with-regex --with-serialization   --with-system --with-program_options --with-filesystem stage 
./b2 install --prefix=/opt/boost-clang-libc++/

Paciente… Paciente… built!

for MongoDB:

git clone https://github.com/mongodb/mongo.git
# Remember that it is a VERY unstable version! You can clone some Tag or download the source code of some mongodb stable version
scons --full install  --64=FORCE64  -j 16 --prefix /opt/mongo-clang-libc++/  --use-system-boost --extrapath=/opt/boost-clang-libc++/ --osx-version-min=10.8 --libc++  # osx-version-min=10.8 is for maverick, you can use 10.7 as well.

Wait, wait… built!

For running mongodb you have to setup where Boost’s Dynamic libraries are:

export DYLD_LIBRARY_PATH=/opt/boost-clang-libc++/lib:$DYLD_LIBRARY_PATH

I suggest you to put it into you .bash_profile

So…
To compile your program that uses, for example, boost_filesystem and the mongodb c++ Library you have to:

clang++ yourprogram.cpp -o program -L/opt/mongo-clang-libc++/lib -lmongoclient /opt/boost-clang-libc++/lib/libboost_filesystem.a

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s