所以我用python 2.7安装了anaconda,并安装了Caffe库的所有需求。 我确保opencv是由安装
import cv2
并检查我可以从文档运行几个例子。
现在我下载caffe,正确configurationmakefile.config并运行make all。 我得到非常奇怪的错误:
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
那家伙怎么了? 请注意,我原来有anaconda3和编译caffe但成功,但我在python3下面临caffe问题,所以我不得不删除它,并尝试使用python 2.7设置为anaconda。
当然,我已经确保libpng16.so.16在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$
我search了这个错误,但没有发现与caffe有关的任何内容。
我遇到了同样的问题,我通过在我的Makefile.config中添加-rpath
来修复它:
LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda/lib
我认为这是正确的修复,因为它(-rpath)告诉GCC在哪里可以找到库(libjpeg,libpng)的其他库(在这种情况下,opencv)所依赖的库。
Per @cel建议 –
ldd libopencv_highgui.so
显示这个lib依赖的文件。 他们中的一些人(不是libpng!)位于我没有包含在makefile.config文件夹中。 将文件夹包含到MakeFile构建成功后。 注意:在建立caffe之后,你可能不会去Spyder进入PythonPath管理器,并将caffe的文件夹添加进去(或者如果你不使用anaconda \ spyder,就把它包含到pythonpath中)。
添加
LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda/lib
在Makefile.config中工作。