In caffe, sometimes, it is convinient to use matlab function to do calculation, like SVD deconposition. But install Matlab API is very annoying.
1, edit Makefile.configure----MATLAB_DIR
In my conputer: MATLAB_DIR := /usr/local/MATLAB/R2013b/
2, compiler matlab API
make matcaffe
3, test whether Matlab API can work well
make mattest
In this step, many problem will arise. since in my computer, Matlab version is 2013b which only support gcc-4.7.x, but my os is fedora with gcc-5.1 inside. When I run make mattest, the first problem also arise frequently on internet:
ibstdc++.so.6: version `GLIBCXX_3.4.21'.
Then I do following the internet:
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
But another problem arised when I run program:
/home/niuyue/cnn_project/caffe-master/matlab/+caffe/private/caffe_.mexa64: undefined symbol:
_ZN2cv8imencodeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputArrayERSt6vectorIhSaIhEERKSB_IiSaIiEE
I search in the internet for long time, but nothing useful got until I find these:
https://github.com/BVLC/caffe/issues/655
https://github.com/kyamagu/mexopencv/issues/64
https://github.com/kyamagu/mexopencv/issues/62#issuecomment-15054244
http://blog.csdn.net/lien0906/article/details/46816243
I find the problem is not only libstdc++, and we also need to replace other libs in Matlab.
export LD_PRELOAD=/usr/lib64/libopencv_highgui.so.2.4:/usr/lib64/libopencv_imgproc.so.2.4:/usr/lib64/libopencv_core.so.2.4:/usr/lib64/libstdc++.so.6:/usr/lib64
/libfreetype.so.6 matlab
export LD_LIBRARY_PATH=/usr/lib64/
Finally, the problem is solved, and I can call caffe function in Matlab.