1

when I run this command to install OpenCV with Python module

cmake ../ -DCMAKE_BUILD_TYPE=RELEASE 
-DCMAKE_INSTALL_PREFIX=/usr/local 
-DBUILD_EXAMPLES=ON 
-DBUILD_NEW_PYTHON_SUPPORT=ON 
-DINSTALL_PYTHON_EXAMPLES=ON 
-DPYTHON_EXECUTABLE=/usr/local/bin/python2.7 
-DPYTHON_INCLUDE_DIR=/usr/local/include/python2.7/ 
-DPYTHON_LIBRARY=/usr/local/lib/python2.7/config/libpython2.7.a 
-DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/lib/python2.7/site-packages/numpy/core/include/ 
-DPYTHON_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages/ 
-DBUILD_PYTHON_SUPPORT=ON

I get this error message.

/usr/bin/ld: /usr/local/lib/python2.7/config/libpython2.7.a(abstract.o): relocation R_X86_64_32 
against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/python2.7/config/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

I can't understand what is wrong and the error message.

Is there someone who can tell me what is wrong with this?

By the way, My OS is CentOS.

and I use Python2.7.5

Anderson
  • 3,139
  • 3
  • 33
  • 45

1 Answers1

8

I answer my own question. hope someone who suffers the same problem find a way out of it in a short time.

1.First of all, just update all pagackages using yum I got several bugs attributed to dependency issues when installing OpenCV.

 sudo yum update --skip-broken

2.Rebuild your Python with "--enable-shared". OpenCV with python module requires the "libpython2.7.so" file to be built correctly. However if you have just built python without this configuration, it's likely that you do not have this file. "libpython2.7.a" is not enough. In my case, when I refer libpython2.7.a to be a python library source it crashed down continuously.

So.. download python 2.7.5 (or something like this), and reconfigure like this.

./configure --enable-shared
make
make install

Now you might get "libpython2.7.so" and "libpython2.7.so.1.0"

3.Build your OpenCV with python module. this is what I coded on installation. I guess this example help you kick your problem out.

cmake ../ -DCMAKE_BUILD_TYPE=RELEASE 
-DCMAKE_INSTALL_PREFIX=/usr/local 
-DBUILD_EXAMPLES=ON 
-DBUILD_NEW_PYTHON_SUPPORT=ON 
-DINSTALL_PYTHON_EXAMPLES=ON 
-DPYTHON_EXECUTABLE=/usr/local/bin/python2.7 
-DPYTHON_INCLUDE_DIR=/usr/local/include/python2.7/ 
-DPYTHON_LIBRARY=/usr/local/lib/libpython2.7.so.1.0 
-DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/lib/python2.7/site-packages/numpy/core/include/ 
-DPYTHON_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages/ 
-DBUILD_PYTHON_SUPPORT=ON

That's all.

Anderson
  • 3,139
  • 3
  • 33
  • 45
  • you can use `-D CMAKE_BUILD_TYPE=RELEASE -D MAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON` rather than all the individual python values (this works with OpenCV 2.4.9 anyway). – ronen Jul 24 '14 at 22:10
  • you may want to use -DPYTHON2_* prefix instead of -DPYTHON_* on new versions of OpenCV. – Paulo Miguel Almeida Oct 08 '15 at 15:03
  • @Anderson I have similar issue Opencv 3.0 on centos , Getting `make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... Linking CXX shared library ../../lib/libopencv_photo.so [ 41%] Built target opencv_photo make: *** [all] Error 2` Can u suggest me – Kamlesh Mar 23 '16 at 11:09