Cross compile Cuberite for Raspberry Pi

Compiling cuberite on a raspberry pi can take a long time. For this problem I looked for a way to cross compile a raspberry pi version. This tutorial should work on debian and on ubuntu based systems.

You will need a linux system for the compiling process, a raspberry pi image and other things too. If you open the terminal then the location should be by default your home location.
We need to do 3 steps. Let's start.

Install Requirements

Packages that are required. Run this command with sudo or as root:

apt-get install git cmake lua5.1

Required for:
  • git - Cloning the raspberry pi tools
  • cmake - Building cuberite
  • lua5.1 - In a build step, generates the c++ bindings for lua

Setting up the gcc cross compiler

  1. Open a terminal, create the directory raspberrypi and cd into it
  2. Clone the raspberrypi tools:
    git clone --depth=1 git://

  3. The path to the bin directory of the cross compiler has to be added to the env PATH. Open and add this line to the end of the file ~/.bashrcexport

  4. Close and reopen the terminal, that the additions to the PATH gets recognized.
  5. Cd back into the directory raspberrypi
  6. Run the command below and you should see a output. If not, then please run ". ~/.bashrc" and try it again

  7. Inside of the directory raspberrypi, create a directory named rootfs. Now the raspberry pi image is required.
  8. For mounting the image the offset of the second partition is required. Run this with sudo or as root:
    fdisk -l <path to raspberry image>

  9. Example of the output:
    Disk 2017-06-21-raspbian-jessie-lite.img: 1,2 GiB, 1304671744 bytes, 2548187 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x5906b8f2
    Device                               Boot Start     End Sectors  Size Id Type
    2017-06-21-raspbian-jessie-lite.img1       8192   93486   85295 41,7M  c W95 FAT32 (LBA)
    2017-06-21-raspbian-jessie-lite.img2      94208 2548186 2453979  1,2G 83 Linux

  10. Multiply the second number under start by 512
    94208 * 512 = 48234496
  11. This command has to be run with sudo or as a root user.
    mount -o offset=48234496 <path to img file> /mnt

  12. Run this commands with sudo or as root, to copy the lib and usr (can take a while is over 1,5 GiB big) directory into the raspberrypi/rootfs directory:
    cp -r /mnt/lib $HOME/raspberrypi/rootfs
    cp -r /mnt/usr $HOME/raspberrypi/rootfs

  13. Run this with sudo or as root, to unmount the raspberry pi image:
    umount /mnt

  14. Create a file named pi.cmake in directory raspberrypi and add this content:
    SET(CMAKE_C_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc)
    SET(CMAKE_CXX_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++)
    SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/raspberrypi/rootfs)

  15. The compiling environment has been setup. Now cd into the cuberite source or clone it if you haven't it
  16. Inside of raspberrypi create the directory Release and cd into it:
    cmake -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake -DCMAKE_BUILD_TYPE=RELEASE ..
  17. For compiling you can add the number of cores / processors it should use. Run nproc to see how many threads are possible, e.g. 4

    make -j<number of cores to use>
    make - Only uses one thread
    "make -j4" - Uses up to 4 cores / processors, if available
  18. If it was successful the executable is inside the directory <path to cuberite>/Server

Install gcc-4.8 and g++-4.8 on the raspberry pi

The executable has been compiled with gcc-4.8 and we need this or a newer version on the raspberry.

Connect to your raspberry pi
  1. Run this command with sudo or as a root user
    apt-get install gcc-4.8 g++-4.8
    Please type /usr/bin/gcc and press 2 times tab and check if you have gcc-4.6. If you have only gcc-4.8, ignore this step. If yes, then we need to set gcc-4.8 and g++-4.8 as default. Run this with sudo or as a root user:
    update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
    update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
    update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
    update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50

Now we are finished. Copy the the directory Server to the raspberry pi and test if it's running.

If you have any questions, problems ask.

Good luck,

Sources used:
Thanks given by: jimmis98 , LogicParrot , xoft
Thanks for this guide. I could never get it working myself. I'll fix it up for the Hard-float builds, now my own pi has died.
Thanks given by:
Can you confirm exactly what you do with the tolua to make it work? I don't see any tolua executable in the folder you said.
Thanks given by:
(12-13-2014, 04:14 AM)bearbin Wrote: Can you confirm exactly what you do with the tolua to make it work? I don't see any tolua executable in the folder you said.

Requirement is a compiled mc server for the computer you are running. The tolua file will be generated at around 16%. Then you should have a file named tolua in this directory:
This file has then to be copied into the directory:

For executing the file tolua, the directory who contains it has to bee added to the environment PATH variable.

Edit: Changed the directory for the tolua to tolua++, it's better
Thanks given by:
Added download link of mc server for raspberry pi.
Thanks given by:
@bearbin and did you got it working the cross compling?
Thanks given by:
Yeah I'm going to work on it but I was away for the weekend this weekend. I have the skeleton code mostly done, and I have wednesday afternoon and thursday free next week so I should be able to get it done then.
Thanks given by:
I removed the download link. You can now download the file from here:
Thanks to @bearbin
Thanks given by:
The download is also available directly from the homepage, which is probably good for newer users.
Thanks given by:
Thanks for the guide, I was able to set up the crosscompiling environment, too. Finally I can compile without turning the Gallery server off Smile
Thanks given by:

Users browsing this thread: 1 Guest(s)