Cross compile Cuberite for Raspberry Pi
#1
Hello!

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 cmake lua5.1 gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf


Required for:
  • gcc-arm-linux-gnueabihf - Contains arm-linux-gnueabihf-gcc. the C Cross Compiler
  • g++-arm-linux-gnueabihf - Contains arm-linux-gnueabihf-cpp, the C++ Cross Compiler
  • 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. Inside of the directory raspberrypi, create a directory named rootfs. Now the raspberry pi image is required.
  3. 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>

  4. Example of the output:
    Disk 2019-07-10-raspbian-buster-lite.img: 2 GiB, 2197815296 bytes, 4292608 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: 0x17869b7d
    
    Device                              Boot  Start    End Sectors  Size Id Type
    2019-07-10-raspbian-buster-lite.img1        8192  532480  524289  256M  c W95 FAT32 (LBA)
    2019-07-10-raspbian-buster-lite.img2      540672 4292607 3751936  1.8G 83 Linux

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

  7. 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

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

  9. Create a file named pi.cmake in directory raspberrypi and add this content:
    SET(CMAKE_SYSTEM_NAME Linux)
    SET(CMAKE_SYSTEM_VERSION 1)
    SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
    SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-cpp)
    SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/raspberrypi/rootfs)
    SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

  10. The compiling environment has been setup. Now cd into the cuberite source or clone it if you haven't it
  11. Inside of raspberrypi create the directory Release and cd into it:
    cmake -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake -DCMAKE_BUILD_TYPE=RELEASE ..
  12. 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
  13. If it was successful the executable is inside the directory <path to cuberite>/Server

Everything completed. Copy the the directory Server to the raspberry pi and test if it's running.

If you have any questions, problems ask.

Good luck,
Seadragon91


Sources used:
http://stackoverflow.com/questions/19162...s-compiler
http://somewideopenspace.wordpress.com/2...pi-wheezy/
http://www.raspberrypi.org/downloads/
Reply
Thanks given by: jimmis98 , LogicParrot , xoft
#2
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.
Reply
Thanks given by:
#3
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.
Reply
Thanks given by:
#4
(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:
Code:
path/to/mc-server/source/Release/lib/tolua++/
This file has then to be copied into the directory:
Code:
~/raspberrypi/tolua++

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
Reply
Thanks given by:
#5
Added download link of mc server for raspberry pi.
Reply
Thanks given by:
#6
@bearbin and did you got it working the cross compling?
Reply
Thanks given by:
#7
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.
Reply
Thanks given by:
#8
I removed the download link. You can now download the file from here:
http://builds.cuberite.org/
Thanks to @bearbin
Reply
Thanks given by:
#9
The download is also available directly from the homepage, which is probably good for newer users.
Reply
Thanks given by:
#10
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
Reply
Thanks given by:




Users browsing this thread: 13 Guest(s)