I am trying to compile caffe with python interface on an Ubuntu 14.04 machine.
I have installed Anaconda and opencv with conda install opencv
. I have also installed all the requirement stipulated in the coffee and changed the commentary blocks in makefile.config
so that PYTHON_LIB and PYTHON_INCLUDE point towards Anaconda distributions.
When I am calling make all
, the following command is issued:
g++ .build_release/tools/caffe.o -o .build_release/tools/caffe.bin -pthread
-fPIC -DNDEBUG -O2 -DWITH_PYTHON_LAYER
-I/home/andrei/anaconda/include
-I/home/andrei/anaconda/include/python2.7
-I/home/andrei/anaconda/lib/python2.7/site-packages/numpy/core/include
-I/usr/local/include
-I/home/andrei/anaconda/lib
-I/lib/x86_64-linux-gnu
-I/lib64
-I/usr/lib/x86_64-linux-gnu
-I.build_release/src
-I./src
-I./include
-I/usr/include
-Wall -Wno-sign-compare -lcaffe
-L/home/andrei/anaconda/lib
-L/home/andrei/anaconda/lib/././
-L/usr/local/lib -L/usr/lib
-L/home/andrei/anaconda/lib/././libpng16.so.16
-L/lib/x86_64-linux-gnu
-L/lib64
-L/usr/lib/x86_64-linux-gnu
-L/usr/lib
-L.build_release/lib
-lcudart -lcublas -lcurand -lglog -lgflags -lprotobuf -lleveldb -lsnappy
-llmdb -lboost_system -lhdf5_hl -lhdf5 -lm
-lopencv_core -lopencv_highgui -lopencv_imgproc -lboost_thread -lstdc++
-lboost_python -lpython2.7 -lcblas -latlas \
-Wl,-rpath,\$ORIGIN/../lib
However, it is stopped by the following set of errors:
/usr/bin/ld: warning: libpng16.so.16, needed by /home/andrei/anaconda/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_create_read_struct@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_interlace_handling@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_IHDR@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_get_io_ptr@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_longjmp_fn@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_gray_to_rgb@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_compression_level@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_bgr@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_filter@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_rgb_to_gray@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_init_io@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_destroy_read_struct@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_swap@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_get_IHDR@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_palette_to_rgb@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_compression_strategy@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_get_tRNS@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_write_info@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_packing@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_read_fn@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_create_info_struct@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_read_end@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_read_update_info@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_write_image@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_write_end@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_expand_gray_1_2_4_to_8@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_create_write_struct@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_read_image@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_read_info@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_strip_alpha@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_write_fn@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_destroy_write_struct@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_error@PNG16_0'
/home/andrei/anaconda/lib/libopencv_highgui.so: undefined reference to `png_set_strip_16@PNG16_0'
Following the advice from this question: Caffe install on ubuntu for anaconda with python 2.7 fails with libpng16.so.16 not found, I tired running the ldd /home/andrei/anaconda/lib/libopencv_highgui
, and obtained the following output:
linux-vdso.so.1 => (0x00007fff1a104000)
libopencv_core.so.2.4 => /home/andrei/anaconda/lib/././libopencv_core.so.2.4 (0x00007ff18e8a0000)
libopencv_imgproc.so.2.4 => /home/andrei/anaconda/lib/././libopencv_imgproc.so.2.4 (0x00007ff18e3f0000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff18e1ec000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff18dfce000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff18ddc6000)
libz.so.1 => /home/andrei/anaconda/lib/././libz.so.1 (0x00007ff18dbb0000)
libjpeg.so.8 => /home/andrei/anaconda/lib/././libjpeg.so.8 (0x00007ff18d979000)
libpng16.so.16 => /home/andrei/anaconda/lib/././libpng16.so.16 (0x00007ff18d737000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007ff18d535000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007ff18d22d000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff18cf29000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff18cc23000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff18ca0d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff18c648000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff18f0d0000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007ff18c40a000)
I then proceeded to add all the required directories into the INCLUDE_DIRS
and LIBRARY_DIRS
of the make.config
file (hence additional -I
and -L
in the g++
call above), including the explicit link to libpng16.so.16
already present in anaconda libraries. This have however not resolved the issue. I also tried adding the file to $LD_LIBRARY_PATH
and $LD_RUN_PATH
, but without any effect.
What might the problem be and how could I resolve it?
It works with me based on the solution here https://github.com/hashdist/hashstack/issues/670
export LD_LIBRARY_PATH=~/anaconda2/lib:$LD_LIBRARY_PATH
This shall be added in ~/.bashrc
or ~/.bash_profile
I came across the same problem. I found it similar to https://github.com/BVLC/caffe/issues/2007, and I solved it by
cd /usr/lib/x86_64-linux-gnu
sudo ln -s ~/anaconda/lib/libpng16.so.16 libpng16.so.16
sudo ldconfig
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With