• Caffe 编译: undefined reference to imencode()



    本系列文章由 @yhl_leo 出品,转载请注明出处。
    文章链接: http://blog.csdn.net/yhl_leo/article/details/52150781


    整理之前编译工程中遇到的一个Bug,贴上提示log信息:

    ...
    
    CXX/LD -o .build_release/examples/siamese/convert_mnist_siamese_data.bin
    .build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
    collect2: error: ld returned 1 exit status
    make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1
    make: *** Waiting for unfinished jobs....
    .build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
    collect2: error: ld returned 1 exit status
    make: *** [.build_release/tools/convert_imageset.bin] Error 1
    .build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
    collect2: error: ld returned 1 exit status
    make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1
    .build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
    collect2: error: ld returned 1 exit status
    make: *** [.build_release/tools/compute_image_mean.bin] Error 1
    .build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
    collect2: error: ld returned 1 exit status
    make: *** [.build_release/tools/caffe.bin] Error 1
    .build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
    collect2: error: ld returned 1 exit status
    make: *** [.build_release/tools/extract_features.bin] Error 1
    .build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)'
    .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)'
    collect2: error: ld returned 1 exit status
    make: *** [.build_release/examples/siamese/convert_mnist_siamese_data.bin] Error 1
    
    ...

    很明显是OpenCV出了问题,网上查阅后,得知是因为lib文件opencv_imgcodecsMakefile文件中未添加,修改如下:

    LIBRARIES += glog gflags protobuf leveldb snappy 
        lmdb boost_system hdf5_hl hdf5 m 
        opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs

    此外,还有一些Makefile文件这么写,也是可行的:

    ifeq ($(USE_OPENCV), 1)
        LIBRARIES += opencv_core opencv_highgui opencv_imgproc 
    
        ifeq ($(OPENCV_VERSION), 3)
            LIBRARIES += opencv_imgcodecs
        endif
    
    endif
  • 相关阅读:
    【poj1195】Mobile phones(二维树状数组)
    【2018年全国多校算法寒假训练营练习比赛(第五场)-E】情人节的电灯泡(二维树状数组单点更新+区间查询)
    【2018年全国多校算法寒假训练营练习比赛(第五场)-G】 送分啦-QAQ(斐波那契博弈)
    【Wannafly挑战赛10
    【2018年全国多校算法寒假训练营练习比赛(第四场)- E】通知小弟(强连通缩点)
    JS中的forEach、$.each、map方法推荐
    关于echarts3地图下钻省市
    Vue2.0总结———vue使用过程常见的一些问题
    我理解的关于Vue.nextTick()的正确使用
    一个用 vue 写的树层级组件 vue-ztree
  • 原文地址:https://www.cnblogs.com/hehehaha/p/6332118.html
Copyright © 2020-2023  润新知