本来caffe的配置用的makefile.config就很麻烦了,还要针对matlab接口进行配置,简直折磨人
首先用于配置的系统环境是ubuntu18.04 + cuda-9.0 + matlab2017b
经过一系列的配置后makefile会执行到
MEX matlab/+caffe/private/caffe_.cpp
进行matlab和caffe之间的编译
然后可能会发现报错如下:
caffe.pb.cc:(.text+0x4e4d3): undefined reference to google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::string*)'
最后的错误信息可能是:
Makefile:518: recipe for target 'matlab/+caffe/private/caffe_.mexa64' failed
make: *** [matlab/+caffe/private/caffe_.mexa64] Error 255
这是由于c++的编译器gcc的版本问题,由于之前为了配置caffe需要将编译器版本降至5.0以下,我选择了4.8。但是实际上这个操作会导致一系列的上述错误信息。
解决方法:
修改Makefile文件(注意不是Makefile.config)在CXXFLAGS += -MMD -MP
这句后面填上CXXFLAGS += -std=c++11
,并且维持之前的5.0以上的gcc的版本不用变化
这里会有个Warning,不用管它,不是Error就没问题啦
虽然前面或许会完美通过,但是当运行make mattest
测试caffe的matlab接口时可能会失败,我的错误包含了以下的信息:
Invalid MEX-file '/home/aiserver/Downloads/mexopencv-3.3.1/+cv/private/VideoCapture_.mexa64':
Missing symbol 'sqlite3_auto_extension'
Missing symbol 'sqlite3_bind_blob'
Missing symbol 'sqlite3_bind_double'
Missing symbol 'sqlite3_bind_int'
Missing symbol 'sqlite3_bind_int64'
Missing symbol 'sqlite3_bind_null'
Missing symbol 'sqlite3_bind_text'
Missing symbol 'sqlite3_changes'
Missing symbol 'sqlite3_clear_bindings'
Missing symbol 'sqlite3_close'
Missing symbol 'sqlite3_column_blob'
Missing symbol 'sqlite3_column_bytes'
Missing symbol 'sqlite3_column_count'
Missing symbol 'sqlite3_column_decltype'
Missing symbol 'sqlite3_column_double'
Missing symbol 'sqlite3_column_int'
Missing symbol 'sqlite3_column_int64'
Missing symbol 'sqlite3_column_name'
Missing symbol 'sqlite3_column_table_name'
Missing symbol 'sqlite3_column_text'
Missing symbol 'sqlite3_column_type'
Missing symbol 'sqlite3_create_function'
Missing symbol 'sqlite3_create_module'
Missing symbol 'sqlite3_create_module_v2'
Missing symbol 'sqlite3_declare_vtab'
Missing symbol 'sqlite3_errcode'
Missing symbol 'sqlite3_errmsg'
Missing symbol 'sqlite3_exec'
Missing symbol 'sqlite3_finalize'
Missing symbol 'sqlite3_free'
Missing symbol 'sqlite3_free_table'
Missing symbol 'sqlite3_get_table'
Missing symbol 'sqlite3_last_insert_rowid'
Missing symbol 'sqlite3_libversion_number'
Missing symbol 'sqlite3_malloc'
Missing symbol 'sqlite3_mprintf'
Missing symbol 'sqlite3_open'
Missing symbol 'sqlite3_open_v2'
Missing symbol 'sqlite3_prepare'
Missing symbol 'sqlite3_prepare_v2'
Missing symbol 'sqlite3_realloc'
Missing symbol 'sqlite3_reset'
Missing symbol 'sqlite3_result_blob'
Missing symbol 'sqlite3_result_double'
Missing symbol 'sqlite3_result_error'
Missing symbol 'sqlite3_result_int'
Missing symbol 'sqlite3_result_int64'
Missing symbol 'sqlite3_result_null'
Missing symbol 'sqlite3_result_text'
Missing symbol 'sqlite3_result_value'
Missing symbol 'sqlite3_snprintf'
Missing symbol 'sqlite3_step'
Missing symbol 'sqlite3_total_changes'
Missing symbol 'sqlite3_user_data'
Missing symbol 'sqlite3_value_blob'
Missing symbol 'sqlite3_value_bytes'
Missing symbol 'sqlite3_value_double'
Missing symbol 'sqlite3_value_int'
Missing symbol 'sqlite3_value_int64'
Missing symbol 'sqlite3_value_numeric_type'
Missing symbol 'sqlite3_value_text'
Missing symbol 'sqlite3_value_type'
Missing symbol 'sqlite3_vfs_find'
Missing symbol 'sqlite3_vfs_register'
Missing symbol 'sqlite3_vfs_unregister'
Missing symbol 'sqlite3_vmprintf'
Missing symbol '_ZN11xercesc_3_111InputSource11setEncodingEPKt'
Missing symbol '_ZN11xercesc_3_111InputSource11setPublicIdEPKt'
Missing symbol '_ZN11xercesc_3_111InputSource11setSystemIdEPKt'
Missing symbol '_ZN11xercesc_3_125DOMImplementationRegistry20getDOMImplementationEPKt'
Missing symbol '_ZN11xercesc_3_19XMLString7releaseEPPtPNS_13MemoryManagerE'
Missing symbol '_ZN11xercesc_3_19XMLString9transcodeEPKtPNS_13MemoryManagerE'
required by
'/usr/lib/libgdal.so.1
->/usr/local/lib/libopencv_imgcodecs.so.3.3
->/usr/local/lib/libopencv_videoio.so.3.3
->/usr/local/lib/libopencv_highgui.so.3.3
->/usr/local/lib/libopencv_features2d.so.3.3
->/usr/local/lib/libopencv_calib3d.so.3.3
->/usr/local/lib/libopencv_cudalegacy.so.3.3
->/usr/local/lib/libopencv_cudaobjdetect.so.3.3
->/home/aiserver/Downloads/mexopencv-3.3.1/+cv/private/VideoCapture_.mexa64'
Missing symbol 'dlclose'
Missing symbol 'dlopen'
Missing symbol 'dlsym'
Missing symbol 'heim_abort'
required by
'/usr/lib/x86_64-linux-gnu/libgssapi.so.3
->/usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2
->/usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4
->/usr/lib/x86_64-linux-gnu/libnetcdf.so.11
->/usr/lib/libgdal.so.1
->/usr/local/lib/libopencv_imgcodecs.so.3.3
->/usr/local/lib/libopencv_videoio.so.3.3
->/usr/local/lib/libopencv_highgui.so.3.3
->/usr/local/lib/libopencv_features2d.so.3.3
->/usr/local/lib/libopencv_calib3d.so.3.3
->/usr/local/lib/libopencv_cudalegacy.so.3.3
->/usr/local/lib/libopencv_cudaobjdetect.so.3.3
->/home/aiserver/Downloads/mexopencv-3.3.1/+cv/private/VideoCapture_.mexa64'
Missing symbol '_et_list'
required by
'/usr/lib/x86_64-linux-gnu/libheimntlm.so.0
->/usr/lib/x86_64-linux-gnu/libgssapi.so.3
->/usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2
->/usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4
->/usr/lib/x86_64-linux-gnu/libnetcdf.so.11
->/usr/lib/libgdal.so.1
->/usr/local/lib/libopencv_imgcodecs.so.3.3
->/usr/local/lib/libopencv_videoio.so.3.3
->/usr/local/lib/libopencv_highgui.so.3.3
->/usr/local/lib/libopencv_features2d.so.3.3
->/usr/local/lib/libopencv_calib3d.so.3.3
->/usr/local/lib/libopencv_cudalegacy.so.3.3
->/usr/local/lib/libopencv_cudaobjdetect.so.3.3
->/home/aiserver/Downloads/mexopencv-3.3.1/+cv/private/VideoCapture_.mexa64'
Missing symbol 'ANannlen'
Missing symbol 'ANannlist'
Missing symbol 'ANend'
Missing symbol 'ANendaccess'
Missing symbol 'ANfileinfo'
Missing symbol 'ANgetdatainfo'
Missing symbol 'ANnumann'
Missing symbol 'ANreadann'
Missing symbol 'ANselect'
Missing symbol 'ANstart'
Missing symbol 'DFdiget'
Missing symbol 'DFdiput'
Missing symbol 'DFdiread'
Missing symbol 'DFdisetup'
Missing symbol 'DFdiwrite'
Missing symbol 'DFKconvert'
Missing symbol 'DFKgetPNSC'
Missing symbol 'DFKislitendNT'
Missing symbol 'DFKisnativeNT'
Missing symbol 'DFKNTsize'
Missing symbol 'DFKsetNT'
Missing symbol 'error_top'
Missing symbol 'HCcreate'
Missing symbol 'HCget_config_info'
Missing symbol 'Hclose'
Missing symbol 'HCPgetcompinfo'
Missing symbol 'HCPgetcompress'
Missing symbol 'HCPgetcomptype'
Missing symbol 'HCPgetdatasize'
Missing symbol 'HDcheck_empty'
Missing symbol 'Hdeldd'
Missing symbol 'HDgetdatainfo'
Missing symbol 'HDget_special_info'
Missing symbol 'HDmemfill'
Missing symbol 'Hendaccess'
Missing symbol 'HEPclear'
Missing symbol 'HEpush'
Missing symbol 'HEvalue'
Missing symbol 'Hgetelement'
Missing symbol 'Hinquire'
Missing symbol 'Hishdf'
Missing symbol 'HLcreate'
Missing symbol 'Hlength'
Missing symbol 'HLgetblockinfo'
Missing symbol 'HMCcreate'
Missing symbol 'HMCreadChunk'
Missing symbol 'HMCsetMaxcache'
Missing symbol 'HMCwriteChunk'
Missing symbol 'Hnewref'
Missing symbol 'Hnextread'
Missing symbol 'Hoffset'
Missing symbol 'Hopen'
Missing symbol 'HPisfile_in_use'
Missing symbol 'HPregister_term_func'
Missing symbol 'Hputelement'
Missing symbol 'Hread'
Missing symbol 'Hseek'
Missing symbol 'Hsetaccesstype'
Missing symbol 'Hsetlength'
Missing symbol 'Hstartaccess'
Missing symbol 'Hstartread'
Missing symbol 'Hwrite'
Missing symbol 'HXcreate'
Missing symbol 'Vaddtagref'
Missing symbol 'Vattach'
Missing symbol 'Vdelete'
Missing symbol 'Vdetach'
Missing symbol 'vexistvg'
Missing symbol 'vexistvs'
Missing symbol 'VFfieldorder'
Missing symbol 'VFfieldtype'
Missing symbol 'Vfindclass'
Missing symbol 'Vfinish'
Missing symbol 'Vgetclass'
Missing symbol 'Vgetnext'
Missing symbol 'Vgettagref'
Missing symbol 'VHmakegroup'
Missing symbol 'VHstoredata'
Missing symbol 'VHstoredatam'
Missing symbol 'Vinitialize'
Missing symbol 'Vinquire'
Missing symbol 'Visvg'
Missing symbol 'Visvs'
Missing symbol 'Vntagrefs'
Missing symbol 'VSattach'
Missing symbol 'VSdelete'
Missing symbol 'VSdetach'
Missing symbol 'VSfdefine'
Missing symbol 'VSgetclass'
Missing symbol 'VSgetdatainfo'
Missing symbol 'VSgetname'
Missing symbol 'VSinquire'
Missing symbol 'VSQueryref'
Missing symbol 'VSread'
Missing symbol 'VSseek'
Missing symbol 'VSsetclass'
Missing symbol 'VSsetfields'
Missing symbol 'VSwrite'
required by
'/usr/lib/libmfhdfalt.so.0
->/usr/lib/libgdal.so.1
->/usr/local/lib/libopencv_imgcodecs.so.3.3
->/usr/local/lib/libopencv_videoio.so.3.3
->/usr/local/lib/libopencv_highgui.so.3.3
->/usr/local/lib/libopencv_features2d.so.3.3
->/usr/local/lib/libopencv_calib3d.so.3.3
->/usr/local/lib/libopencv_cudalegacy.so.3.3
->/usr/local/lib/libopencv_cudaobjdetect.so.3.3
->/home/aiserver/Downloads/mexopencv-3.3.1/+cv/private/VideoCapture_.mexa64'
Missing symbol 'th_comment_add'
Missing symbol 'th_comment_add_tag'
Missing symbol 'th_comment_clear'
Missing symbol 'th_comment_init'
Missing symbol 'th_comment_query'
Missing symbol 'th_comment_query_count'
required by
'/usr/lib/x86_64-linux-gnu/libtheoraenc.so.1
->/usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56
->/usr/local/lib/libopencv_videoio.so.3.3
->/usr/local/lib/libopencv_highgui.so.3.3
->/usr/local/lib/libopencv_features2d.so.3.3
->/usr/local/lib/libopencv_calib3d.so.3.3
->/usr/local/lib/libopencv_cudalegacy.so.3.3
->/usr/local/lib/libopencv_cudaobjdetect.so.3.3
->/home/aiserver/Downloads/mexopencv-3.3.1/+cv/private/VideoCapture_.mexa64'
查询github和stackoverflow后经过漫长的尝试后,发现是OpenCV安装的时候配置了GDAL库及其依赖项,而且因为采用的OpenCV库的安装方式是sudo apt-get install
的方式,我也不能设定是否关闭GDAL,所以我改用源码编译的方式重头安装OpenCV:
我先下载了OpenCV 3.3.1,cmake没问题,但是make的时候不幸的,又报错了:
[ 53%] Building CXX object modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/core.cpp.o
/usr/bin/cmake: /home/ztgong/local/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/ztgong/local/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
[ 53%] Building CXX object modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/arithm.cpp.o
[ 53%] Building CXX object modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/reductions.cpp.o
/usr/bin/cmake: /home/ztgong/local/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
[ 53%] Building CXX object modules/cudaarithm/CMakeFiles/opencv_cudaarithm.dir/src/element_operations.cpp.o
/usr/bin/cmake: /home/ztgong/local/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
[ 53%] Linking CXX static library ../../lib/libopencv_cudaarithm.a
/usr/bin/cmake: /home/ztgong/local/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/ztgong/local/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
/usr/bin/cmake: /home/ztgong/local/anaconda2/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake)
[ 53%] Built target opencv_cudaarithm
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
再一次的查找,发现我的CUDA是9.0,但是貌似OpenCV 3.3.x只支持到CUDA8.0,所以才有如上的算法兼容性的错误。
所以我选择了不用CUDA 8.0,采用了OpenCV 3.4.1,这时顺利安装通过,然后重新make caffe的matlab接口然后 make mattest
,完美通过!