Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Python Linker Error

I've been trying to install opencv on heroku to no avail. I've tried using heroku-anvil for the installation and am now trying to install opencv via the bash shell. First I installed cmake but then when I try to make opencv I inevitably get the following error:

Linking CXX shared library ../../lib/cv2.so
/usr/bin/ld: /usr/local/lib/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/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

Here are the exact commands that I'm using:

# connect to bash shell

heroku run bash
cd /tmp

# Downloading and Installing cmake:

curl -s http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.Z > cmake.tar.gz
tar zxf cmake.tar.gz
cd cmake-2.8.12.1/
./bootstrap
make
make install

# Download and Install OpenCV

curl -s https://s3.amazonaws.com/nerdglasses/opencv/OpenCV-2.4.2.tar.bz2 > opencv.tar.gz
tar xf opencv.tar.gz
cd OpenCV-2.4.2/
../cmake-2.8.12.1/bin/cmake -DBUILD_SHARED_LIBS=NO -DCMAKE_SHARED_LINKER_FLAGS="-fPIC" -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DWITH_OPENEXR=OFF -DCMAKE_FIND_ROOT_PATH=/app/.heroku -DCMAKE_INSTALL_PREFIX=/app/.heroku .
make # ERROR HERE

Anyone know how to fix this? Or if there is a better way to get opencv installed on heroku for a python web app?

like image 969
Peter Tseng Avatar asked Dec 16 '13 22:12

Peter Tseng


1 Answers

You need to reinstall python with shared and static way.

Firstly, download Python source file again.

and then..

./configure --enable-shared --enable-static
make
make install

In that way you might solve this problem out.

Here's the link that you might want to know.

Installing OpenCV with python module on CentOS goes wrong

like image 117
Anderson Avatar answered Oct 22 '22 11:10

Anderson