Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake with -DBUILD_matlab=ON fails #2078

Closed
wookayin opened this issue Mar 9, 2015 · 3 comments
Closed

cmake with -DBUILD_matlab=ON fails #2078

wookayin opened this issue Mar 9, 2015 · 3 comments

Comments

@wookayin
Copy link

wookayin commented Mar 9, 2015

Hello, I suspect that this might be a bug introduced after the commit 3d30510 (PR #2059).

The environment with which I've tested is: Mac OS X 10.10. I haven't tested with Ubuntu, since I don't have any Linux machine with matlab installed as of now.

$ cd build
$ cmake .. -DBUILD_matlab=ON && make -j4

However, building matcaffe fails with the message ld: library not found for -lpython2.

[100%] Building Matlab interface: ${CAFFE_ROOT}/matlab/caffe/caffe.mexmaci64
Building with 'Xcode Clang++'.
ld: library not found for -lpython2
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Let's see the command line argument passed (absolute paths were replaced by ${CAFFE_ROOT}).
There are python-related link flags, -lpython2 and -lboost_python-mt, which were added from ${PYTHON_LIBRARIES}

/Applications/MATLAB_R2014b.app/bin/mex -output ${CAFFE_ROOT}/matlab/caffe/caffe.mexmaci64 ${CAFFE_ROOT}/matlab/caffe/matcaffe.cpp -DCPU_ONLY -DWITH_PYTHON_LAYER -DGTEST_USE_OWN_TR1_TUPLE -I${CAFFE_ROOT}/src -I/usr/local/include -I${CAFFE_ROOT}/build/include -I/usr/local/include/opencv -I/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Versions/Current/Headers -I/System/Library/Frameworks/Python.framework/Headers -I/usr/local/lib/python2.7/site-packages/numpy/core/include -I${CAFFE_ROOT}/include -I${CAFFE_ROOT}/build -L${CAFFE_ROOT}/build/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -L/usr/lib -lcaffe -lboost_system-mt -lboost_thread-mt -lglog -lgflags -lhdf5_hl -lhdf5 -llmdb -lleveldb -lsnappy -lopencv_core -lopencv_highgui -lopencv_imgproc -lcblas -lpython2  -lboost_python-mt -lprotobuf -v

The reason why ld fails might be that the ordering of link flags (-L and -l) has changed in the internal invocation, and thus it was not able to link the python2 dynamic module.

... (omitted) ...
/usr/bin/xcrun -sdk macosx10.9 (..omitted...)
-lcaffe  -lboost_system-mt  -lboost_thread-mt  -lglog  -lgflags -lhdf5_hl  -lhdf5  -llmdb  -lleveldb  -lsnappy  -lopencv_core  -lopencv_highgui  -lopencv_imgproc  -lcblas  -lpython2  -lboost_python-mt  -lprotobuf   -L${CAFFE_ROOT}/build/lib  -L/usr/local/lib  -L/usr/local/lib  -L/usr/local/lib  -L/usr/local/lib  -L/usr/lib  -L"/Applications/MATLAB_R2014b.app/bin/maci64" -lmx -lmex -lmat -o "${CAFFE_ROOT}matlab/caffe/caffe.mexmaci64

This build step with cmake, succeeds prior to 3d30510.

As I am doubtful these flags (e.g. -lpython) are necessary to build matlab targets, these flags could be removed when building matlab bindings so that the build could be successful out-of-box. Currently, I tried a workaround setting BUILD_python_layer to OFF, but after inspection to find better solution, I think I could submit a PR to fix this. Thanks.

@eshelman
Copy link

eshelman commented Apr 8, 2015

I am experiencing the same issue (but on Scientific Linux 6.6 with the g++ compiler). From what I can tell, the issue is that the compilation line is using -lpython2 instead of the actual Python version, such as -lpython2.7

The flag -lpython2 tells the linker to look for a library file named libpython2.so. As far as I can tell, no version of Python has shipped such a file for ages.

It's possible to work around this by manually changing that flag to -lpython2.7. You can also create a symlink from libpython2.so to libpython2.7.so (although that's a nasty hack).

Because python doesn't need to be linked here, the cleanest would be to remove the -lpython2 from the Matlab build line. I'm submitting a pull request with the change.

@adinriv
Copy link

adinriv commented Jul 21, 2016

Just for completeness, this answer (http://stackoverflow.com/a/35286218/424986) solves the problem of missing lbypthon2 library with Matlab by updating the CMake rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants