7

On Mac OS Maverick I have installed OpenCV with a brew install opencv.

I created a simple program (copied from this tutorial). Compilation worked fine but when running the executable I get the following error:

dyld: Library not loaded: /usr/local/lib/libpng16.16.dylib
  Referenced from: /usr/local/lib/libopencv_highgui.2.4.dylib
  Reason: Incompatible library version: libopencv_highgui.2.4.dylib requires version 33.0.0 or later, but libpng16.16.dylib provides version 32.0.0
Trace/BPT trap: 5

I checked that libpngwas properly installed via brew install libpng and ran a brew upgrade to make sure everything was up-to-date.

Running locate libpng16.dylib returns:

/Applications/GIMP.app/Contents/Resources/lib/libpng16.16.dylib
/usr/local/Cellar/libpng/1.6.10/lib/libpng16.16.dylib
/usr/local/Cellar/libpng/1.6.12/lib/libpng16.16.dylib
/usr/local/Cellar/libpng/1.6.13/lib/libpng16.16.dylib
/usr/local/Cellar/libpng/1.6.15/lib/libpng16.16.dylib
/usr/local/lib/libpng16.16.dylib

Any idea?

sdabet
  • 17,379
  • 11
  • 73
  • 143

3 Answers3

4

The best solution is to fully uninstall libpng and re-install it:

$ sudo brew uninstall libpng
$ sudo rm '/usr/local/bin/libpng-config'
$ for i in `brew link --overwrite --dry-run libpng`; do sudo rm $i; done
$ sudo brew install libpng

If you need to install opencv:

$ sudo brew tap homebrew/science
$ sudo brew install opencv
JonasCz
  • 11,174
  • 6
  • 40
  • 61
2

Homebrew should ensure that you the correct dependencies install. However, it's possible that you have more than one version of libpng16 installed at different paths. Have a look in...

/usr/lib
/opt/local/lib

If you find any versions of the library in these locations then they may be causing the wrong one to be loaded when your program starts. As a quick fix you can try typing DYLD_LIBRARY_PATH=/usr/local/lib before your program name on the command line. In the longer term you may need to remove the conflicting versions altogether.

gmbeard
  • 624
  • 6
  • 18
  • 1
    There are several versions of `libpng16` in my `/usr/local/Cellar/libpng` folder (but none in `/usr/lib` or `/opt/local/lib`). And the one in `/usr/locale/lib` (which is obviously loaded by dylib) is a symlink to the latest version in `/usr/local/Cellar/libpng/1.6.16`). So it looks correct to me, isn't it? – sdabet Jan 24 '15 at 11:11
  • 1
    If there are no other version elsewhere then it doesn't look like a version conflict. It seems that you need a newer version of `libpng`. I'd have thought that Homebrew would've installed the correct dependencies though – gmbeard Jan 24 '15 at 11:15
  • 1
    You're right. I've just downloaded, built and installed the latest version of `libpng` and it works fine now. Thanks. – sdabet Jan 24 '15 at 11:33
  • 4
    Just had the same update `brew update && brew upgrade libpng` worked for me. Upgraded from `libpng.1.6.15` to `libpng.1.6.16` my issue was opencv related as well. – ThomasReggi Mar 25 '15 at 03:28
  • Remove brew's libpng, and download source and compile did work – Rex Jul 07 '16 at 09:17
2

This answer is for OSX users who installed through Conda, more specifically the conda-forge channel (I'm not sure about others).

Conda ends up installing its own libpng in the environment and you can update it with conda upgrade libpng.

I guess this is basically a bug with the opencv recipe on conda-forge.

KobeJohn
  • 6,630
  • 5
  • 36
  • 59