Fix error loading shared libraries: cannot open shared object file

Posted on 263 views

Did you get an error message “error while loading shared libraries: cannot open shared object file” while trying to install or build an application on Ubuntu, Debian, CentOS/RHEL or Amazon Linux system that depends on libpng library?. libpng is the official extensible PNG reference library that supports almost all PNG features, and has been extensively tested for over 23 years.

You can easily install libpng by building from source on a Linux system. I’ll be performing the installation to fix “error loading shared libraries: cannot open shared object file” on a CentOS 7 system. But first we’ll need to install build tools.

# CentOS / Amazon Linux / Oracle Linux
sudo yum -y groupinstall "Development Tools"

# Ubuntu / Debian
sudo apt-get update
sudo apt-get install build-essential

Confirm make and gcc tools are installed.

$ gcc --version
gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-12)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

$ make --version
GNU Make 3.82
Built for x86_64-koji-linux-gnu
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Then download the latest release of libpng from sourceforge.


Extract the file once downloaded:

tar xvf libpng-1.6.37.tar.gz

Run the configure command inside the directory created after file extraction.

cd libpng-1.6.37/

Run make command after success in the previous command execution.


Finally install libpng library in your Linux system.

$ sudo make install

Here is my successful installation message.

make  install-data-hook
make[3]: Entering directory `/home/ec2-user/libpng-1.6.37'
+ cd /usr/local/include
+ for f in pnglibconf.h png.h pngconf.h
+ rm -f pnglibconf.h
+ ln -s libpng16/pnglibconf.h pnglibconf.h
+ for f in pnglibconf.h png.h pngconf.h
+ rm -f png.h
+ ln -s libpng16/png.h png.h
+ for f in pnglibconf.h png.h pngconf.h
+ rm -f pngconf.h
+ ln -s libpng16/pngconf.h pngconf.h
+ cd /usr/local/lib/pkgconfig
+ rm -f libpng.pc
+ ln -s libpng16.pc libpng.pc
make[3]: Leaving directory `/home/ec2-user/libpng-1.6.37'
make[2]: Leaving directory `/home/ec2-user/libpng-1.6.37'
make[1]: Leaving directory `/home/ec2-user/libpng-1.6.37'

After installation you should be able to locate file.

$ sudo find / -name

You can then continue to build the application that depends on libpng library.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.