L’installation de Caffe sur Ubuntu pour Anaconda avec Python 2.7 échoue avec libpng16.so.16 introuvable

J’ai donc installé anaconda avec python 2.7 et installé toutes les exigences de la bibliothèque Caffe. Je me suis assuré que opencv est installé par

import cv2 

Et vérifier que je peux exécuter quelques exemples de documents.

Maintenant, je télécharge caffe, configurez makefile.config correctement et lancez make all. J’ai une erreur très étrange:

 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_ssortingp_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_ssortingp_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 

Qu’est-ce qui ne va pas avec ce gars? Notez que j’avais à l’origine anaconda3 et caffe compilé pour cela mais avec succès mais j’ai dû faire face à des tonnes de problèmes avec caffe sous python3, alors j’ai dû le supprimer et essayer de le configurer pour anaconda avec python 2.7.

Et bien sûr, j’ai veillé à ce que libpng16.so.16 soit en 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$ 

J’ai googlé l’erreur, mais je n’ai rien trouvé par rapport à Caffe.

J’ai rencontré le même problème et j’ai corrigé en ajoutant un -rpath dans mon Makefile.config:

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

Je pense que c’est le correctif correct car il (-rpath) indique à GCC où il peut trouver des bibliothèques (libjpeg, libpng) que d’autres bibliothèques (dans ce cas, opencv) dépendent.

Par suggestion @cel –

 ldd libopencv_highgui.so 

montre les fichiers dont dépend cette lib Deux d’entre eux (pas le libpng!) Se trouvaient dans le dossier que je n’ai pas inclus dans le fichier makefile.config. Après avoir inclus leur dossier dans MakeFile, la construction a réussi. Remarque: après la construction du caffe, vous ne pourrez pas aller dans Spyder dans le gestionnaire PythonPath et y append le dossier de caffe (ou simplement l’inclure dans pythonpath si vous n’utilisez pas anaconda \ spyder).

Ajouter

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

dans Makefile.config travaillé.