Compiling opencv with python support error

I am trying to install opencv with python support and I am facing a problem that I cannot help.

When I set up a project with cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..

, it gets set up and says python support.

--   Python:
--     Interpreter:                 /usr/local/bin/python2 (ver 2.7.10)
--     Libraries:                   /usr/local/lib/libpython2.7.a (ver 2.7.10)
--     numpy:                       /usr/local/lib/python2.7/site-packages/numpy/core/include (ver 1.9.2)
--     packages path:               lib/python2.7/site-packages

      

When I try make

it, it fails at

[ 75%] Built target opencv_test_contrib
Linking CXX shared library ../../lib/cv2.so
/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython2.7.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/cv2.so] Error 1
make[1]: *** [modules/python/CMakeFiles/opencv_python.dir/all] Error 2
make: *** [all] Error 2

      

It just works fine without python support.

I didn't understand what this error means / how to fix it as I don't have much experience with cmake. Any help for debugging this is appreciated.

+3


source to share


1 answer


As the error says, you need to recompile the "-fPIC" flag. Some studies are pulling up an easy fix. Add to the team -D CMAKE_C_FLAGS=-fPIC

, so your whole teamcmake -D CMAKE_C_FLAGS=-fPIC -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..



Please advise the rest of the internet if this works or not.

0


source







All Articles