Opencv 2.4.1 instalation libpng error

Now I am hardly working on my research project, It uses Opencv for image processing. Then I heard about opencv latest version released (2.4.1). This post is about an error that I got when I was going to install Opencv 2.4.1. This post does not explaining all about Opencv installation. If you need complete installation guide, just google it.

The error that I got when compiling the Opencv source is,

Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libpng.a(
pngget.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpng.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.2.4.
1] Error 1
make[1]: *** [modules/highgui/CMakeFiles/
opencv_highgui.dir/all] Error 2
make: *** [all] Error 2

When I got this error I search on google but I could not find any solution for that. Here is the solution that I suggest and it succeed  for me.

According to my point of view this can be occurred version mismatch between Opencv's libpng and libpng installed on your system. But there is a libpng already included in opencv source download. So you can use that libpng to compile opencv source.

Solution
The error saying about libpng package therefore if you get this error too, you should set a flag BUIL_PNG = on when configure the cmake make file generation process. This allow opencv to compile its source using libpng source that include in the opencv source directory. I used cmake GUI to generate make file on Ubuntu. Here you can easily set that flag on as you can see on following figure.



That's it now you can compile opencv without this error.
So happy opencv coding!

Continue Reading...