This guide should help you with cross-compiling other software as well (at least give you some pointers if you’re new to this).

So, I got a Synology NAS. It’s a Linux box running on x86_64 (AKA AMD64), but it has no nano. My laptop is a Mac, running on aarch64 (AKA ARM64).

So, I decided to fire up an Ubuntu (20.04) VM on my laptop, and statically cross-compile nano, to get a single binary I could just drop into my NAS.

Installing the compiler and libraries

sudo apt install build-essential gcc-x86-64-linux-gnu libncurses-dev

However, to statically compile this, we also need the x86_64 version of the library installed (which will then be “packed” into the final binary, that’s how static compiling works).

Create the file /etc/apt/sources.list.d/amd64.list with the following content:

deb [arch=amd64] focal-security  main restricted universe multiverse
deb [arch=amd64]  focal           main restricted universe multiverse
deb [arch=amd64]  focal-updates   main restricted universe multiverse
deb [arch=amd64]  focal-backports main restricted universe multiverse

Make sure to replace “focal” with whatever distro you are using. These are the Ubuntu repos for amd64 (x86_64), which we need to obtain the amd64 version of packages.

Now update the package list and add the architecture:

sudo apt update
sudo dpkg --add-architecture amd64
sudo apt update

Now install the x86_64 version of libncurses-dev:

sudo apt install libncurses-dev:amd64

That should be all, let’s continue!

Getting the source and building

tar xf nano-6.2.tar.xz
cd nano-6.2/
CC=x86_64-linux-gnu-gcc ./configure --host x86_64 CFLAGS="-O2 -Wall --static"

Now when we run find . -name nano we will find exactly one binary built at src/nano.

Let’s verify that it built as x86_64, and that it’s statically linked:

file src/nano

Which outputs:

src/nano: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=838510eaef96345242a4e9adcc29001a8722f1af, for GNU/Linux 3.2.0, not stripped

We can see “x86-64” and “statically linked”. Sounds good! Deploy it on your x86_64 NAS on /usr/local/bin to install nano system-wide. You can do that with SCP. Make sure to test it, though.

I find it amusing, BTW. Usually one is on x86_64, cross-compiling for an embedded device running aarch64… But this time, it’s the other way around. (:

Either way, no more VIM! :D

If this guide helped you out, consider donating a coffee. (: