1

I'm trying to install OpenCV 3.3.0 based on these instructions:
http://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
But I faced errors while running :

sudo cmake -D CMAKE_BUILD_TYPE=RELEASE 
           -D CMAKE_INSTALL_PREFIX=/usr/local     
           -D INSTALL_PYTHON_EXAMPLES=ON   
           -D INSTALL_C_EXAMPLES=OFF      
           -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules 
           -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python     
           -D BUILD_EXAMPLES=ON ..

Here's my output in CLI: CLI Output

A few minutes ago my cmake command was working properly but I had errors in make -j4 command which was:

/usr/bin/ld: /usr/local/lib/libavformat.a(allformats.o): relocation R_X86_64_32 against `ff_aac_demuxer' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavformat.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:312: recipe for target 'lib/libopencv_videoio.so.3.3.0' failed
make[2]: *** [lib/libopencv_videoio.so.3.3.0] Error 1
CMakeFiles/Makefile2:4918: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/all' failed
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

But After I ran my cmake command with fPIC It started to show errors on cmake.The command I executed for fPIC option:

sudo cmake -D CMAKE_BUILD_TYPE=RELEASE \
 -D CMAKE_INSTALL_PREFIX=/usr/local \
 -D INSTALL_PYTHON_EXAMPLES=ON \
 -D INSTALL_C_EXAMPLES=OFF \
 -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
 -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \
 -D BUILD_EXAMPLES=ON \
 -D COMPILE_FLAGS+=-fPIC ..

My OS is Ubuntu 16.04 and I want to install openCV with python3 as interface.
Thanks in advance.

NavidIvanian
  • 347
  • 5
  • 15
  • Check if you have two different files named `libavformat.a` in `/usr/local/lib` and `/usr/local/lib/x86_64-linux-gnu/`. Also was the error same when you compiled with the flag `-fPIC` – Lakshya Kejriwal Sep 16 '17 at 21:33
  • Line "Configuring incomplete. Error occured!" means that the error has been occured **before**. Show exact error message (as text). BTW, `COMPILER_FLAGS+=fPIC` is wrong syntax for CMake. – Tsyvarev Sep 16 '17 at 21:47
  • @lakshyaKejriwal It seems that I don't have this path:`/usr/local/lib/x86_64-linux-gnu/`.Compiling with `-fPIC` showes these 2 lines:`-- Configuring incomplete, errors occurred! See also "/home/navid/opencv-3.3.0/build/CMakeFiles/CMakeOutput.log". See also "/home/navid/opencv-3.3.0/build/CMakeFiles/CMakeError.log".` – NavidIvanian Sep 16 '17 at 21:52
  • @Tsyvarev Here's my complete output:https://pastebin.com/VehVjVED. I can't understand what you mean by error message?Are you asking for the content of CMakeError.log? – NavidIvanian Sep 16 '17 at 21:54
  • In all probability you have two different `libavformat.a`. Try to locate them using the command `locate -i libavformat.a` – Lakshya Kejriwal Sep 16 '17 at 22:11
  • @LakshyaKejriwal,The locations are:`/usr/lib/x86_64-linux-gnu/libavformat.a` and `/usr/local/lib/libavformat.a` – NavidIvanian Sep 16 '17 at 22:16
  • Try removing the file in `/usr/local/lib/` and create a copy of it in some other location. – Lakshya Kejriwal Sep 16 '17 at 22:40
  • @LakshyaKejriwal,what do you mean by some other location?Where am I supposed to copy that file and why? – NavidIvanian Sep 16 '17 at 22:44
  • @LakshyaKejriwal,I removed `libavformata` and copied it in my home.However the situation is still the same as before! – NavidIvanian Sep 16 '17 at 23:02
  • Try compiling it without `-fPIC` now and if there is an error then what is it? – Lakshya Kejriwal Sep 16 '17 at 23:04
  • @LakshyaKejriwal,You can find complete output here:https://pastebin.com/1Vmvn0Cw. Here's my `CMakeError.log`:https://pastebin.com/Hs1SMDmJ – NavidIvanian Sep 16 '17 at 23:08
  • Did you install `libv4l-dev`? – Lakshya Kejriwal Sep 16 '17 at 23:15
  • @LakshyaKejriwal,`libv4l-dev is already the newest version (1.10.0-1)`. I think there might be some unmet dependencies due I used to get errors in compiling videoio as I copied the error above. – NavidIvanian Sep 16 '17 at 23:16
  • Try passing the parameter `-D WITH_LIBV4L=OFF` to cmake along with other parameters – Lakshya Kejriwal Sep 16 '17 at 23:19
  • @LakshyaKejriwal,No change.`sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D BUILD_EXAMPLES=ON -D WITH_LIBV4L=OFF ..` – NavidIvanian Sep 16 '17 at 23:22
  • 1
    The **first error message** in the CMake log is `CMake Error at cmake/OpenCVModule.cmake:305 (message):`. But even before it strange things are happens: `The imported target "vtkRenderingPythonTkWidgets" references the file` ... `but this file does not exist.`. Looks like your library installation is broken. – Tsyvarev Sep 16 '17 at 23:26
  • 1
    @Tsyvarev,I checked what you said.It's searching for `/home/navid/opencv_contrib-3.1.0/modules` while I have installed 3.3.0 version.How should I change that so it can find `/home/navid/opencv_contrib-3.3.0/modules`? – NavidIvanian Sep 16 '17 at 23:42
  • @Tsyvarev,I renamed that file and now cmake is completed successfully but when I run `make -j4` the error i mentioned above is shown. :( – NavidIvanian Sep 17 '17 at 01:35
  • 1
    `the error i mentioned above is shown.` - Is this error about "recompile with -fPIC"? If so, the error means that `libavformat` library should be compiled with shared libraries, not OpenCV one. See that SO question: https://stackoverflow.com/questions/13812185/how-to-recompile-with-fpic. – Tsyvarev Sep 17 '17 at 08:00
  • @Tsyvarev, unfortunately I'm unfamiliar with compiling and other stuff.How should I do that? – NavidIvanian Sep 17 '17 at 11:02
  • You have found instructions for compile OpenCV, probably by googling them. What is wrong in google the same for `libaformat` library? – Tsyvarev Sep 17 '17 at 12:16
  • I googled but I didn't found much things about compiling `libavformat` with shared libs. Besides, I tried cmake with `-D BUILD_SHARED_LIBS=ON` and it was done successfully but I got errors in `make` again. – NavidIvanian Sep 17 '17 at 12:35

0 Answers0