So I have installed anaconda with python 2.7 and installed all of the requirements for Caffe library. I ensured that opencv is installed by
import cv2
And checking that I can run couple of examples from docs.
Now I download caffe, configure makefile.config properly and run make all. I get very odd error:
make
CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin
/usr/bin/ld: warning: libpng16.so.16, needed by /home/maxkhk/anaconda/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_create_read_struct@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_interlace_handling@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_IHDR@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_get_io_ptr@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_longjmp_fn@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_gray_to_rgb@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_compression_level@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_bgr@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_filter@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_rgb_to_gray@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_init_io@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_destroy_read_struct@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_swap@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_get_IHDR@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_palette_to_rgb@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_compression_strategy@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_get_tRNS@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_write_info@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_packing@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_read_fn@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_create_info_struct@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_read_end@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_read_update_info@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_write_image@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_write_end@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_expand_gray_1_2_4_to_8@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_create_write_struct@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_read_image@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_read_info@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_strip_alpha@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_write_fn@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_destroy_write_struct@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_error@PNG16_0'
/home/maxkhk/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_strip_16@PNG16_0'
collect2: error: ld returned 1 exit status
Makefile:560: recipe for target '.build_release/tools/upgrade_net_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1
What's wrong with that guy? Notice that I originally had anaconda3 and compiled caffe for it but successfully but I faced tons of issues with caffe under python3, so I had to remove it and try to set it up for anaconda with python 2.7.
And of course I have ensured that libpng16.so.16 is in anaconda:
maxkhk@maxkhk-X550DP:~/anaconda$ find -name libpng16.so.16
./pkgs/libpng-1.6.17-0/lib/libpng16.so.16
./lib/libpng16.so.16
maxkhk@maxkhk-X550DP:~/anaconda$
I googled the error, but haven't found anything in relation to caffe.
I ran into the same problem and I fixed it by adding an
-rpath
in my Makefile.config :LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda/lib
I think this is the correct fix because it (-rpath) tells GCC where it can find libraries (libjpeg, libpng) that other libraries (in this case opencv) depend on.
Per @cel suggestion -
shows the files on which this lib depends. Couple of them (not the libpng!) were located in folder which I haven't included into the makefile.config. After including their folder into MakeFile build succeeded. Notice: after building the caffe you may won't to go in Spyder into the PythonPath manager and add the caffe's folder into it (or just include it into pythonpath if you are not using anaconda\spyder).
Adding
in to Makefile.config worked.