1

I'm trying to install opencv to my Ubuntu 14.04 machine using the documentation provided in

http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation

However, during the compilation process I get the following error.

Linking CXX shared library ../../lib/libopencv_videoio.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_videoio.so.3.0.0] Error 1
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [all] Error 2

I noticed a few posts mentioning similar errors and some solutions suggest removing the libavcodec.a from /usr/local/lib/. I'd like not to do that as I need ffmpeg libraries in the machine as well.

Could someone please help me to resolve this issue?.

Thanks

slhck
  • 36,575
  • 28
  • 148
  • 201
userDtrm
  • 533
  • 2
  • 7
  • 20
  • Did you try the suggestion in the error message 'recompile with -fPIC' ? – Ha Dang Mar 10 '15 at 10:15
  • Yes. I tried editing the cmake list file by adding set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" ). But that didn't work. I also tried to recompile ffmpeg with --enable-shared. But that didn't work as well. – userDtrm Mar 10 '15 at 11:48
  • Did you try to remove the libavcodec.a from the folder /usr/local/lib then rerun the compilation? You can move libavcodec.a to somewhere else then put it back to /usr/local/lib once you've done with opencv compilation. – Ha Dang Mar 10 '15 at 12:08
  • I had to remove libavformat.a libavutil.a libavcodec.a libswscale.a from /usr/local/lib and then compile opencv. Then the removed files were copied back to the location. It seems to have worked. Thanks a lot for the help. – userDtrm Mar 10 '15 at 18:14
  • Glad that it works. Have fun OpenCV-ing! :-) – Ha Dang Mar 10 '15 at 21:36

2 Answers2

0

I got it to work (for installing ffmpeg) by simply reinstalling the whole thing from the beginning with all instances of $ ./configure replaced by $ ./configure --enable-shared (first make sure to delete all the folders and files including the .so files from the previous attempt).

Apparently this works because https://stackoverflow.com/a/13812368/10593190.

And this matches with @camino's comment on https://stackoverflow.com/a/19365454/10593190 and XavierStuvw's answer.

V Li
  • 169
  • 2
  • 7
0

Just run these 2 lines in your terminal/environment:

pip install opencv-python==3.4.5.20
pip install opencv-contrib-python==3.4.5.20
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Mohit Verma
  • 56
  • 1
  • 6