Compile librespot for kernel prior 3.9 - librespot-org/librespot GitHub Wiki

This has been taken from here and has since been updated. Thanks to @bjoerns1983 for the original write up.

On devices with modern Linux Kernels (3.9 onwards) Librespot works without any problems, but if you try to use it with older Kernels and use the discovery feature (no User/Pass required while starting Librespot) you might run into an error.

The error could look something like this:

INFO:librespot: librespot ddfc28f (2017-08-04). Built on 2017-08-07. Build ID: N5RcEuis thread 'main' 
panicked at 'calledResult::unwrap()on anErrvalue: Error { repr: Os { code: 92, message: "Protocol not 
available" } }', /checkout/src/libcore/result.rs:860 note: Run withRUST_BACKTRACE=1 for a backtrace.

This happens because the used mdns solutions tries to use the Kernel Option SO_REUSEPORT which was introduced in Kernel Version 3.9. That could be a problem for you if you use for example an Orange Pi with the Mainline Kernel, because that is stuck at Version 3.4 (ridiculous).

The good thing is you can build a Version of Librespot yourself which does not have that problem. The user jr01 pointed me in the right direction Github Issue.

It is not very complicated, but do yourself a favour and try not to build it using your Orange Pi. It will take ages, if it ever finishes. Tried it for four hours an than gave up. Just use a Linux box or a suitable VM.

Because we will use the Docker Script provided by Paul the only thing you need is a Linux Box with Docker and git. I will not explain how to install Linux or Docker, there are tons of guides for this out there.

Once you have installed these things it is pretty easy.

First of all clone the Librespot Repo as well as the rust-mdns Repo from Github:

git clone https://github.com/librespot-org/librespot.git
git clone https://github.com/plietar/rust-mdns.git

Now we must „patch“ rust-mdns so it does not use the SO_REUSEPORT call. This is quiet simple. Go to rust-mdns->src->address_family.rs and search for the line that says .reuse_port(true)? and simply delete that line. Dont forget to save the file.

Move the whole rust-mdns folder to the librespot folder. Now change into the librespot folder and edit the file Cargo.toml. Under [dependencies] search for the line mdns = { git = „https://github.com/plietar/rust-mdns“ } an delete it. Scroll a bit back up and add the following lines before the [dependencies] block:

[dependencies.mdns]
path = "mdns"

That was it. So we patched out the Reuse Port call and than told cargo that it should use the local patched Version of rust-mdns instead of the github Version.

Now we can use docker to compile librespot for it. Easy now, you only need to be inside the librespot folder for it:

docker build -t librespot-cross -f contrib/Dockerfile .
docker run -v /tmp/librespot-build:/build librespot-cross

After a couple of minutes you should be able to collect librespot from /tmp/librespot-build

That build should be able to be used on a variety of devices which do not ship with modern Kernels. Have fun