Error with homebrew + opencv + libpng

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

I created a simple program (copied from this tutorial ). The compilation worked fine, but when I run 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 libpng was installed correctly through brew install libpng and ran 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?

+7
c ++ libpng opencv macos
source share
3 answers

Homebrew should make sure that you install the correct dependencies. However, it is possible that you have more than one version of libpng16 installed on different paths. Look at ...

 /usr/lib /opt/local/lib 

If you find any versions of the library in these places, they may cause incorrect loading at the start of your program. As a quick fix, you can try DYLD_LIBRARY_PATH=/usr/local/lib in front of your program name on the command line. In the long run, you may need to remove conflicting versions altogether.

+2
source share

The best solution is to completely remove libpng and reinstall 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 
+4
source share

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

Conda completes the installation of its own libpng in the environment, and you can upgrade it with conda upgrade libpng .

I assume this is basically a bug with the opencv recipe for conda-forge.

+2
source share

All Articles