在构建MatCaffe(Caffe的Matlab包装器)期间,我遇到以下错误:
[ 96%] Built target convert_mnist_data
[ 96%] Built target convert_mnist_siamese_data
[ 98%] Built target pycaffe
[100%] Building Matlab interface: /home/trunks/Downloads/caffe-master/matlab/+caffe/private/caffe_.mexa64
Building with 'g++'.
Warning: You are using gcc version '4.8.2'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
Warning: You are using gcc version '4.8.2-19ubuntu1)'. The version of gcc is not supported. The version currently supported with MEX is '4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release.
/usr/bin/ld: cannot find -lpython2
collect2: error: ld returned 1 exit status
make[2]: *** [../matlab/+caffe/private/caffe_.mexa64] Error 255
make[1]: *** [matlab/CMakeFiles/matlab.dir/all] Error 2
make: *** [all] Error 2
仔细检查后,我发现使用以下命令,以下文件导致上述错误:
grep -rnw "./" -e "-lpython2"
它向我揭示了以下内容:
./matlab/CMakeFiles/matlab.dir/build.make:53: cd /home/trunks/Downloads/caffe-master/build/matlab && /usr/local/MATLAB/R2014a/bin/mex -output /home/trunks/Downloads/caffe-master/matlab/+caffe/private/caffe_.mexa64 /home/trunks/Downloads/caffe-master/matlab/+caffe/private/caffe_.cpp -DCPU_ONLY -DWITH_PYTHON_LAYER -DGTEST_USE_OWN_TR1_TUPLE -I/home/trunks/Downloads/caffe-master/src -I/usr/include -I/home/trunks/Downloads/caffe-master/build/external/glog-install/include -I/home/trunks/Downloads/caffe-master/build/external/gflags-install/include -I/home/trunks/Downloads/caffe-master/build/include -I/usr/local/include/opencv -I/usr/local/include -I/usr/include/python2.7 -I/home/trunks/anaconda/lib/python2.7/site-packages/numpy/core/include -I/home/trunks/Downloads/caffe-master/include -I/home/trunks/Downloads/caffe-master/build -L/home/trunks/Downloads/caffe-master/build/lib -L/usr/lib/x86_64-linux-gnu -L/home/trunks/Downloads/caffe-master/build/external/gflags-install/lib -L/home/trunks/Downloads/caffe-master/build/external/glog-install/lib -L/usr/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -lcaffe -lboost_system -lboost_thread -lpthread -lgflags -lglog -lhdf5_hl -lhdf5 -llmdb -lleveldb -lsnappy -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopenblas -lpython2 -lboost_python -lprotobuf
因此,我将相应的-lpython2更改为-lpython2.7,希望能解决问题。但是没有收益。
我也尝试了以下内容:
我编辑了/ cmake-master中的默认CMakeLists.txt文件,以更改某些默认设置。我发现Caffe中CMakeLists.txt中的默认python版本设置是2。
//指定要使用的python版本 PYTHON_VERSION:STRING = 2.7
我将其更改为2,并在新的构建文件夹中重复了整个configure-generate-make过程。但是没有收益。每次相同的matlab / build.make文件都显示-lpython2,并且直接将其更改为2.7不会产生。
任何坚实的帮助都将深表感谢。我在Ubuntu 14.04上使用MATLAB 2014a。
答案 0 :(得分:3)
这是因为Utils.cmake中的description
函数存在错误,会将caffe_parse_linker_libs
转换为/usr/lib/x86_64-linux-gnu/libpython2.7.so
这可以通过替换(在cmake / Utils.cmake中)修复
-lpython2
<强>与强>
elseif(IS_ABSOLUTE ${lib})
get_filename_component(name_we ${lib} NAME_WE)
get_filename_component(folder ${lib} PATH)
string(REGEX MATCH "^lib(.*)" __match ${name_we})
list(APPEND libflags -l${CMAKE_MATCH_1})
list(APPEND folders ${folder})
else()
更新的功能正确地将elseif(IS_ABSOLUTE ${lib})
get_filename_component(folder ${lib} PATH)
get_filename_component(filename ${lib} NAME)
string(REGEX REPLACE "\\.[^.]*$" "" filename_without_shortest_ext ${filename})
string(REGEX MATCH "^lib(.*)" __match ${filename_without_shortest_ext})
list(APPEND libflags -l${CMAKE_MATCH_1})
list(APPEND folders ${folder})
else()
转换为/usr/lib/x86_64-linux-gnu/libpython2.7.so
答案 1 :(得分:0)
根据错误消息和命令,导致它,似乎python库安装在异常位置,因此ld
(链接器)无法在其默认路径中找到它。由于CMake脚本已找到标题,因此它还应设置mex
可执行文件以便与库本身一起使用,但由于某种原因它不会。
使构建包工作的最简单方法是将LD_LIBRARY_PATH
设置为python库所在的目录,然后运行make
。如果您想修复CMake脚本,这wiki可能对您有所帮助。
答案 2 :(得分:0)
感谢@Tsyvarev的回答。我发现了一个相当简单的解决方我刚刚创建了一个符号链接(libpython2.so),它指向/ usr / lib文件夹中的libpython2.7.so。这解决了这个问题。 libpython2.7.so也出现在/ usr / lib中,所以我不认为这是一个不寻常的安装问题。
答案 3 :(得分:0)
我遇到了同样的问题。我绝望地从-lpython2
build-matlab/matlab/CMakeFiles/matlab.dir/build.make
之后它确实编译了,似乎无论如何都找到了它需要的东西。
答案 4 :(得分:0)
我遇到了这个问题,它似乎源于Cmake的不可靠性,以获得不同版本的python,例如“libpython.so.1.0”。我将我的CMakeCache.txt文件更改为“libpython.so”,问题解决了。它不仅适用于python,我的“cudnn”也存在这个问题,而且这个解决方案解决了这个问题。