[resolved] Did ubuntu break my rust?


I recently updated to Ubuntu 18.04. And of course I also recently updated nightly rust. I’m not sure which caused the problem, though I suspect the former. Edit: same problem with stable 1.25

Since around the same time, I can’t build a number of rust programs that use native libs. Most seem to be related to libz but I’m not certain that all of them are; there are several different failures. I haven’t looked carefully at all cases; there might be some that involve other libs and this is just a common one.

The simplest is probably a failure to link when trying to cargo install bat, as below:

 [.......] "-Wl,--end-group" "/home/dan/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-795361e8a622f052.rlib" "-Wl,-Bdynamic" "-l" "z" "-l" "c" "-l" "util" "-l" "util" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util" "-l" "util"
  = note: /usr/bin/x86_64-linux-gnu-ld: cannot find -lz
          collect2: error: ld returned 1 exit status

Other cases seem to occur in configure/CMake routines when building other crates, such as libssh2-sys, that in turn depend on libz.

I’m most definitely not missing libz:

 1 lrwxrwxrwx 1 root root     14 May 23  2017 /lib/x86_64-linux-gnu/libz.so.1 -> libz.so.1.2.11
81 -rw-r--r-- 1 root root 116960 May 23  2017 /lib/x86_64-linux-gnu/libz.so.1.2.11

What’s going on here? Do I need to clear some cargo dependency when the underlying OS is upgraded? Does the libz-sys crate need an update somehow?


That’s the runtime library – you need libz.so (no version suffix) to actually link it. It looks like that package is called zlib1g-dev. Perhaps you had that installed before, and something about the upgrade removed it?


:man_facepalming: Of course.

# apt-cache policy zlib1g-dev
  Installed: (none)
  Candidate: 1:1.2.11.dfsg-0ubuntu2
  Version table:
     1:1.2.11.dfsg-0ubuntu2 500
        500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages

Apparently so. I guess the -sys crates carry their own copies of (or processed versions of) the C header files? Otherwise there would have been an earlier error failing to find those – and that would have more obviously clued me in to a missing -dev package.

Many thanks.