3

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.

Maksim Khaitovich
  • 4,742
  • 7
  • 39
  • 70
  • 1
    You may want to include all the dynamic library that are linked in `libopencv_highgui.so` - I think `ldd` does that in linux. – cel Aug 12 '15 at 11:22
  • Sorry, I am not strong in Linux, is it just 'ldd' in terminal? Or some other command? – Maksim Khaitovich Aug 12 '15 at 11:35
  • Should be just `ldd ` in terminal. I am not using linux, so am not perfectly sure, though. – cel Aug 12 '15 at 11:36
  • @cel thanks for the clue, after I have done it I saw that some of libs (not png one) were in the folder which I haven't included. I added them into makefile.config and the build is successful. BUT! After make all and make pycaffe run fine, I also successfully run make test and make runtest (it says that tests are passed). BUT! I can't import caffe in my anaconda. It just says that there is no such module – Maksim Khaitovich Aug 12 '15 at 21:12
  • 1
    @cel disregard. In Spyder I opened tools\pythonpathmanager and added caffe/python folder there. Now works. Please post your comment as an answer so that I could accept it. – Maksim Khaitovich Aug 12 '15 at 21:14
  • Glad you could solve it. Feel free to post an answer yourself! – cel Aug 12 '15 at 21:20
  • I am currently having the same issue. Unfortunately, for me adding all directories revealed by `ldd` to the INCLUDE_DIRS and LIB_DIRS variables in the makefile.config did not help. I also tried to explicitely point the `ld` to the libpng16.so.16 by using the $LD_RUN_PATH and $LD_LIBRARY_PATH as specified in the ld documentation, but with no avail. – chiffa Sep 04 '15 at 18:54

3 Answers3

7

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.

Julien
  • 934
  • 5
  • 17
  • @ccppjava , thank you your answer exactly helped with this problem and one produced by LINKFLAGSS solution. – Il'ya Zhenin Jan 13 '16 at 12:41
  • be careful about this solution, it might cause error: groups.google.com/forum/#!topic/caffe-users/8erM4hbR110 this is due to anaconda might have newer lib than system one, instead, I suggest edit .bashrc add export LD_LIBRARY_PATH=/lib/x86_64-linux-gnu:/home/username/anaconda2/lib:$LD_LIBRARY_PATH – ccppjava Feb 18 '16 at 15:21
1

Per @cel suggestion -

ldd libopencv_highgui.so 

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).

Maksim Khaitovich
  • 4,742
  • 7
  • 39
  • 70
  • So what were the folders and where did you include them in the configs? – chiffa Sep 04 '15 at 17:33
  • I tried to do the same thing and to add the missing libraries into the LIB_DIRS, but with no success. – chiffa Sep 04 '15 at 17:51
  • 1
    @chiffa for me I had to add LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /lib/x86_64-linux-gnu/ and it worked – Maksim Khaitovich Sep 07 '15 at 22:42
  • Thanks for your response, but it is definetely not working for me. I started a new question here http://stackoverflow.com/questions/32405035/caffe-installation-opencv-libpng16-so-16-linkage-issues and filled in an issue on their GitHub issue tracker. – chiffa Sep 08 '15 at 19:01
1

Adding

LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda/lib

in to Makefile.config worked.

Shaido
  • 27,497
  • 23
  • 70
  • 73
Jonathan
  • 823
  • 7
  • 6