When I compile a Crystal app in ubuntu 16.04 it “binds” to libevent-2.0.so.5, but when installed on a ubuntu 18.04 machine it won’t start and instead report:
error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
as ubuntu 18.04 only comes with libevent-2.1.
Is there a way around this or do we need to compile one version of the app per OS version?
With Linux that’s generally how it is: an application is expected to be compiled specifically for the system.
Alternatively, you can ship all the libraries (usually except libc) with the application.
I’d recommend you to compile statically your app. It can be done in any Alpine Linux system. If you have Docker installed, you can look at https://hub.docker.com/r/jrei/crystal-alpine
Yes, that’s what I’ve ended up doing, but with Vagrant. Noticed though that Alpine 3.7 have conflicts between libressl and openssl, so Alpine 3.6 was required for me to compile Crystal applications.
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
config.vm.define "alpine" do |node|
node.vm.box = "alpine/alpine64"
node.vm.box_version = "3.6.0"
node.vm.provision "shell", inline: <<~SHELL
apk update
apk upgrade
apk add crystal shards libc-dev libxml2-dev openssl-dev readline-dev gmp-dev yaml-dev
SHELL
end
config.vm.define "ubuntu" do |node|
node.vm.box = "ubuntu/bionic64"
node.vm.provision "shell", inline: <<~SHELL
apt-key adv --keyserver keys.gnupg.net --recv-keys 09617FD37CC06B54
echo "deb https://dist.crystal-lang.org/apt crystal main" > /etc/apt/sources.list.d/crystal.list
apt-get update
apt-get install -y crystal help2man lintian
SHELL
end
end