OpenCV Error - "recompiling with -fPIC"

I am building a small installation of OpenCV on Ubuntu 13.10, and it looks like something is unfortunate. I went through several versions and installed the methods, and when I go "make" or "make -j4", the truck continues to be transported until

/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 

Any help is appreciated. Thanks again, Robert.

+7
ubuntu opencv
source share
3 answers

I had the same problem when compiling opencv3 alpha on Ubuntu 14.04 with FFMPEG enabled. My FFMPEG was a git version compiled with ./configure make make install

I had to recompile FFMPEG with ./configure --enable-nonfree --enable-pic --enable-shared

This did the trick for me, and after that opencv3 compiled a fine.

+13
source share

I was looking for a way to build OpenCV 2.4.11 correctly, and that was done. However, the correct general parameter is --enable-shared, so on the command line

./configure --enable-nonfree --enable-pic --enable-shared

Thank you for message!

+1
source share

OpenCV did not find the correct ffmpeg lib when the link /usr/local/lib/libavcodec.a in lib/libopencv_videoio.so.3.0.0 .

A libavcodec.so should be provided, but opencv will only find libavcodec.a . What for? There are some possibilities:

1) Old / New ffmpeg

In /usr/local/lib and /usr/local/bin the old ffmpeg with only static libs is installed. Installed a new ffmpeg with a common sheet and a custom installation path, but the system does not know this. You must follow http://code.opencv.org/issues/1077 .

2) No general ffmpeg

You must install ffmpeg with a shared lib, as other people have said.

3) the new ffmpeg does not "install" correctly

If the new ffmpeg is built from the source code and in the setup path, the path should be an absolute path. For example:

 /configure --prefix="$HOME/lib/ffmpeg_build" 

If a relative path is set, the relative path will be set to the ffmpeg settings file, and opencv will not find the required libraries according to the file. You might want to look into the CMakeCache file in the opencv source directory, it will write the libs paths in the building.

+1
source share

All Articles