Solved libpng16.so.16 not found

I have just installed a fresh FreeBSD 10.1 RELEASE on AMD64 and have installed packages (not ports) using
Code:
pkg install -y <package name>
Some of my applications fail:
Code:
$ xfe
Shared object "libpng16.so.16" not found, required by "xfe"
$ firefox
XPCOMGlueLoad error for file /usr/local/lib/firefox/libxul.so:
Shared object "libpng16.so.16" not found, required by "libxul.so"
Couldn't load XPCOM.
$ libreoffice
Shared object "libpng16.so.16" not found, required by "oosplash"
I've discovered what's going by browsing pkg() etc. but am posting the solution here in case it helps anyone else tripped up by this simple issue.
 
This may feel like a FreeBSD install issue, since fresh install of RELEASE-10.1 followed by fresh install of packages leads to missing library files but it's to do with pkg install being less aggressive in updating dependencies than pkg upgrade. If you read through the various man pages such as pkg() and pkg-install() etc or use pkg help install and pkg help upgrade etc you'll get the idea.

You can confirm that some packages require dependencies that are not available in a fresh RELEASE even immediately after a fresh install:
Code:
# pkg info libreoffice | grep png # shows pkg required
libpng16.so.16
# pkg info -ix png # shows pkg currently available
png-1.5.21
You can get lists of missing shared libraries too:
Code:
# pkg check --shlibs -nva | grep -v done
pkg: (feh-2.12_1) /usr/local/bin/feh - required shared library libpng16.so.16 not found
pkg: (fox16-1.6.49_5) /usr/local/bin/shutterbug - required shared library libpng16.so.16 not found
pkg: (gegl-0.2.0_14) /usr/local/bin/gegl - required shared library libpng16.so.16 not found
pkg: (gimp-app-2.8.14_1,1) /usr/local/libexec/gimp/2.2/plug-ins/file-ico - required shared library libpng16.so.16 not found
. . .

You can then view the upgrades that are wanted and available:
Code:
# pkg version -vRL=
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
binutils-2.24_1  <  needs updating (remote has 2.25)
cairo-1.12.18,2  <  needs updating (remote has 1.12.18_1,2)
freetype2-2.5.4  <  needs updating (remote has 2.5.4_1)
gdk-pixbuf2-2.31.2  <  needs updating (remote has 2.31.2_1)
indexinfo-0.2  <  needs updating (remote has 0.2.2)
png-1.5.21  <  needs updating (remote has 1.6.16)
vim-7.4.542  <  needs updating (remote has 7.4.560)
xv-3.10a_15  <  needs updating (remote has 3.10a_16)

You then just need to run a simple pkg upgrade to fetch them. I believe this is because install is not as aggressive as upgrade in retrieving dependencies. You can do a dry run to see 'what if' before you go
Code:
# pkg upgrade -n
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
Checking for upgrades (8 candidates): 100%
Processing candidates (8 candidates): 100%
The following 8 packages will be affected (of 0 checked):

Installed packages to be UPGRADED:
xv: 3.10a_15 -> 3.10a_16
vim: 7.4.542 -> 7.4.560
png: 1.5.21 -> 1.6.16
indexinfo: 0.2 -> 0.2.2
gdk-pixbuf2: 2.31.2 -> 2.31.2_1
freetype2: 2.5.4 -> 2.5.4_1
cairo: 1.12.18,2 -> 1.12.18_1,2
binutils: 2.24_1 -> 2.25

The operation will free 3 MB.
12 MB to be downloaded.
And once you've done it for real you should be able to confirm 100% up to date:
Code:
# pkg check --shlibs -a
Checking all packages: 100%
 
Back
Top