Cross Compile MongoDB for ARM

MongoDB is an document-oriented nosql server. Currently MongoDB(latest verstion 2.6.3) doesn't support ARM. I have a cubieboard, which is an arm-based mini pc. I want MongoDB to run on my cubieboard. Unfortunately, debian wheezy doesn't provide MongoDB package. I have to compile it myself. I tried to compile it ON my cubieboard, but compilation time was too long and at the end cubieboard didn't have enough time to generate mongod executable. My only choice is to cross-compile it and that's all what this blog is about.

Requirement

Before hand, you have to set up a building environment. For me, I installed 32bit linux mint in a virtual machine and did all job on mint. A cross-compile suite is needed. This can be obtained from linaro gcc toolchain. Download its binary build and extract it. Add the path of its bin directory to PATH for mint to find it.

Also you need SCons, a software construction tool. On a debian-based linux, e.g mint, you can acquire it easily by

sudo apt-get install scons

Building

First, download source code from MongoDB's website and extract it to anywhere you like. I will use DIR_TOP to indicate the top-level directory of MongoDB source code.

Before starting to compile, a few modifications have to be made on MongoDB source.

Find DIR_TOP/src/third_party/v8/src/ia32/cpu-ia32.cc Look up for a line that says '

asm("int $3");

Comment it, so this line should look like

//asm("int $3");

According to its code context, this may be related to debugging. We don't need to debug it. It's ok to disable it.

Then find DIR_TOP/src/third_party/v8/src/globals.h Look up for a code block

// Check for supported combinations of host and target architectures.
#if defined(V8_TARGET_ARCH_IA32) && !defined(V8_HOST_ARCH_IA32)
#error Target architecture ia32 is only supported on ia32 host
#endif

Comment the #error to disable it. The code should be like this

// Check for supported combinations of host and target architectures.
#if defined(V8_TARGET_ARCH_IA32) && !defined(V8_HOST_ARCH_IA32)
//#error Target architecture ia32 is only supported on ia32 host
#endif

That's all for modification.

One more thing to do is to tell scons to use linux enviroment variable, such as PATH, CXXFLAGS, etc. This is important if your cross compiler is not in linux executable search path(/bin, /usr/bin, etc). To do this, you have to append --propagate-shell-environment to scons.

Finally, use

scons --propagate-shell-environment --cc=arm-linux-gnueabihf-gcc --cxx=arm-linux-gnueabihf-g++ --full install --prefix=INSTALL_DIR

to compile and install MongoDB.

INSTALL_DIR is where you put your MongoDB build. --cc tells scons to use a c language compiler you provide. --cxx tells scons to use a c++ compiler. arm-linux-gnueabihf-gcc is the cross-compile gcc shipped with linaro gcc toolchain. arm-linux-gnueabihf-g++ is for g++. Names of these two executables may vary depending on the toolchain you use.

Binary Provided

I have compiled MongoDB 2.6.3 for ARM. You can DOWNLOAD it.

Note

Although all executable of MongDB is built, mongo can not be executed.

mongo is a command client used to interact with mongod server.

I have tested all other executables. They are ok. When you execute mongo, it says

ERROR: Binary compiled with -mfloat-abi=hard but without -DUSE_EABI_HARDFLOAT

Even I recompile it with -DUSE_EABI_HARDFLOAT, when executed it says

Segmentation fault

I don't know if this is caused by a bug or it's a compatibility issue because of unoffical support for ARM from MongoDB. However, this isn't a problem, because we have many client alternatives(MongoVUE, Rockmongo, e.t. ).

Enjoy your MongoDB.