Fix error loading shared libraries: libpng16.so.16: cannot open shared object file

Did you get an error message “error while loading shared libraries: libpng16.so.16: 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: libpng16.so.16: cannot open shared object file” on a CentOS 9 system. But first we’ll need to install build tools.

# CentOS / Oracle Linux / Rocky Linux / AlmaLinux / Amazon Linux / RHEL-based Liux Distros 
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 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ make --version
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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.

wget https://sourceforge.net/projects/libpng/files/libpng16/1.6.48/libpng-1.6.48.tar.gz

Extract the file once downloaded:

tar xvf libpng-1.6.48.tar.gz

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

cd libpng-1.6.48/
./configure

Run make command after success in the previous command execution.

make

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.48'
+ 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.48'
make[2]: Leaving directory `/home/ec2-user/libpng-1.6.48'
make[1]: Leaving directory `/home/ec2-user/libpng-1.6.48'

After installation you should be able to locate libpng16.so.16 file.

$ sudo find / -name libpng16.so.16
/usr/local/lib/libpng16.so.16
/home/ec2-user/libpng-1.6.48/.libs/libpng16.so.16

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

More guides on our website:

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Unlock the Right Solutions with Confidence

At CloudSpinx, we don’t just offer services - we deliver clarity, direction, and results. Whether you're navigating cloud adoption, scaling infrastructure, or solving DevOps challenges, our seasoned experts help you make smart, strategic decisions with total confidence. Let us turn complexity into opportunity and bring your vision to life.

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

In today’s guide we will walk you through the steps to install Kotlin Programming Language on Linux Mint | Ubuntu. […]

Bauh is a graphical interface for managing Linux applications/ packages. It currently supports Arch (repositories/AUR), AppImage, Snap, Flatpak and native […]

Performing regular backups of your files in Linux operating systems is a critical part of personal data security and overall […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.