'zlib deployment breaks Ubuntu
I'm trying to use zlib as a dependency on a C++ project. For instance, i'm trying to build the zlib 1.2.8 with make on Ubuntu 20.04 LTS. I'm using the following command line:
./configure --enable-shared
make
make install
/sbin/ldconfig
The main problem is that after this proccess, basically, everything on ubuntu stops working. I am unable to open the notepad, for example. After a reboot, I get stuck on a "pre-boot" screen:
dev/sda5: clean, ****/**** files, ****/**** blocks
I'm using a cloud machine and on a command line access I could se the following error. Here a slice of the log (the error repeats for many lines):
Apr 22 14:20:49 test-ubuntu: /usr/lib/gdm3/gdm-wayland-session[1082]: /usr/libexec/gnome-session-binary: /usr/local/lib/libz.so.1: version `ZLIB_1.2.9' not found (required by /lib/x86_64-linux-gnu/lib
png16.so.16)
...
Apr 22 14:20:49 test-ubuntu: /usr/libexec/goa-deamon: /usr/local/lib/libz.so.1: version 'ZLIB_1.2.9' not found (required by /lib/x86_64-linux-gnu/libpng16.so.16)
...
As a cloud environment, I can't just "stick an USB" to fix the Ubuntu installation. I also tried with Ubuntu 18.04, but both use zlib 1.2.11
as default version. I used the following snippet to get this information:
$ python
>>> import zlib
>>> zlib.ZLIB_VERSION
'1.2.11'
I need to use the zlib 1.2.8 and Ubuntu system. How can I put them together without any "explosion"?
Solution 1:[1]
You should almost never install custom build libraries into system wide paths. Your operating system has got a package manager for a reason. It keeps all the correct versions and build configurations of the different system components together. If you mess with anything there don't expect your system to be working any longer.
Dependencies to C++ projects should be installed into a seperate local directory. You can do that either automatically by using some kind of dependency manager like conan or do it manually with the following configure option:
./configure --prefix=<my_local_install_path> --enable-shared
make
make install
The <my_local_install_path>
can be any path that is not used by the system linker. If you don't need root permissions for the make install
, you should be fine.
You need of course tell your project where to find the custom compiled version of zlib. The exact way of how to do this is dependent on what build system you are using. In cmake you set CMAKE_PREFIX_PATH=<my_local_install_path>
on the commandline. If using plain compiler commands you need to specify the path to the linker via -L<my_local_install_path>
. Note that in the second case (if using shared zlib), you would also need to tell the program at runtime where to find the library (e.g. by setting the LD_LIBRARY_PATH
variable before running the program).
Edit
I just noted, that you intended to install an older version of zlib, than the system default. Is there a reason for that. I don't think zlib is the type of library that changes the api so much, that it is impossible to adhere to a newer version. Did you try with the system default version? Most likely you only need a small fix, to be able to use the new (system default) version.
Solution 2:[2]
Solution
According to the following answer https://stackoverflow.com/a/72013629/8589033, I could fix my problem. The main point was that I were using the linux default lib
storage. After building zlib's shared object it replaced the original (correct version) file. After a reboot, the system couldn't find the correct library.
As fix, i changed the makefile target path. I created another folder to keep my libraries.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | George Victor |