-1

I had a need to run the Ubuntu utility "convert", and when I did I got an error message that my version of libpng was out of date and had to be updated. So, I went the usual route of "apt-get install", but for reasons I now no longer remember, this didn't solve the problem. This is where things got messy. I downloaded the source for libpng, did a make, and a make install. I now have the following files in /usr/local/lib:

-rw-r--r-- 1 root root 821564 2015-09-11 18:37 /usr/local/lib/libpng16.a
-rwxr-xr-x 1 root root    937 2015-09-11 18:37 /usr/local/lib/libpng16.la
lrwxrwxrwx 1 root root     19 2015-09-11 18:37 /usr/local/lib/libpng16.so -> libpng16.so.16.18.0
lrwxrwxrwx 1 root root     19 2015-09-11 18:37 /usr/local/lib/libpng16.so.16 -> libpng16.so.16.18.0
-rwxr-xr-x 1 root root 602132 2015-09-11 18:37 /usr/local/lib/libpng16.so.16.18.0
lrwxrwxrwx 1 root root     10 2015-09-11 18:37 /usr/local/lib/libpng.a -> libpng16.a
lrwxrwxrwx 1 root root     11 2015-09-11 18:37 /usr/local/lib/libpng.la -> libpng16.la
lrwxrwxrwx 1 root root     11 2015-09-11 18:37 /usr/local/lib/libpng.so -> libpng16.so

... which looks reasonable to me. However, now when I run "convert" I get an error message:

convert: error while loading shared libraries: libpng.so.2: cannot open shared object file: No such file or directory

In desperation I created the following link:

lrwxrwxrwx 1 root root     34 2015-09-11 18:39 /usr/local/lib/libpng.so.2 -> /usr/local/lib/libpng16.so.16.18.0

But I get the same error message from convert. Obviously I'm now out of my depth, and would appreciate any hints about how to proceed.

Peter P
  • 39
  • 5

1 Answers1

1

You can check where a program is loading libraries from via the LD_DEBUG environment variable. For example, you could run:

LD_DEBUG=all convert

To see a ton of debugging information. You could run:

LD_DEBUG=libs convert

To see a list of all the libraries convert is dynamically loading. In your case, you can be more specific by running:

LD_DEBUG=libs convert 2>&1 | grep -i png

Sample Output


     20939: find library=libpng12.so.0 [0]; searching
     20939:   trying file=/lib/i386-linux-gnu/libpng12.so.0
     20939: calling init: /lib/i386-linux-gnu/libpng12.so.0
  -quality value       JPEG/MIFF/PNG compression level
     20939: calling fini: /lib/i386-linux-gnu/libpng12.so.0 [0]

You can also use the ldd command, ie: ldd convert to achieve similar results, as noted by @meuh.

Now, to call out the elephant in the room: Ubuntu has package management via apt for a reason: so you don't break your dependencies. If you truly need a newer version of a library, you should:

  • Pull the prebuilt package from LaunchPad.net. At least this way it's a package that can be reverted/uninstalled with minimal hassle in the future.
  • Use a "make install" capture/packaging tool like checkinstall. It captures the output files/changes from the "make install" stage of building a package from source, so you can treat it like a normal package, rather than having to hunt down and manually purge/delete the files generated by directly running make install. You should only be doing this on systems where you are expected to manually handle deps, like good ol' Slackware. :)

In the future...

Rather than installing libpng directly, you could just build it via make, copy the libraries/binaries to a temporary folder (ie: /home/yourname/tmp), and run convert via:

LD_LIBRARY_PATH=/home/yourname/tmp convert

This will cause the provided path to be the first place the program you launch searches when resolving shared objects. It will find your local build of libpng there, and nothing else. Perfect way to test individual libraries without hosing your entire system.

Cloud
  • 17,212
  • 12
  • 64
  • 137
  • 1
    there's also the `ldd` command. – meuh Sep 12 '15 at 13:20
  • @meuh That is correct. I went this route because I wanted to segue into using `LD_LIBRARY_PATH` for future testing. I'll update the answer to mention this. – Cloud Sep 12 '15 at 13:22
  • Thanks for the insight. I can now see where convert is looking for the library, and its – Peter P Sep 12 '15 at 16:08
  • ...(clumsy fingers!) clearly not finding it. When I use apt-get install, I'm told that the version I'm trying to install is already the newest version, so nothing happens. Anyway, apparently I'm not in the right place for this topic, so I'll say "thanks for your help" and goodbye. – Peter P Sep 12 '15 at 16:12
  • @PeterP When you install via `apt`, it has a system catalog of installed binaries, libraries, etc. When you install a source package via `make install`, it doesn't touch the catalog. You likely already have the latest libPNG installed for your system, but you've manually moved/deleted files without letting the system know, since you didn't use `apt` or `dpkg` to do it. – Cloud Sep 12 '15 at 16:33
  • I've reposted this question on SuperUser, and reframed it to ask: "Is there some way I can clean this mess up?" And Dogbert, thanks for taking the time to help me. Much appreciated. – Peter P Sep 12 '15 at 16:36