I am trying to install opencv with python support and I am facing with an issue which I cant help on.
When I configure the 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 configures and says python support present.
-- 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 to 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 builds just fine without python support.
I did not understand what this error means / how to fix this as I dont have much experience with cmake. Any help to debug this is appreciated.
As the error says, you need to recompile with the "-fPIC" flag. Some research pulls up the easy fix. Add to the command -D CMAKE_C_FLAGS=-fPIC
, so that your whole command is cmake -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 let the rest of the internet know if this works or not.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.