Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV make fails - "recompile with -fPIC"

Tags:

opencv

ubuntu

I'm putting together a little OpenCV install on Ubuntu 13.10, and it looks like something is unhappy. I've been through a few versions and install methods, and when I go "make" or "make -j4" the make trucks along 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.

like image 278
Robert Talamantez Avatar asked Aug 28 '14 00:08

Robert Talamantez


2 Answers

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

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

That did the trick for me and after that opencv3 compiled fine.

like image 155
d00d Avatar answered Oct 14 '22 10:10

d00d


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

A libavcodec.so should be provided, but opencv only find a libavcodec.a. Why? there are some possibilities:

1) Old/New ffmpeg

An old ffmpeg with only static libs is installed in /usr/local/lib and /usr/local/bin. A new ffmpeg with shared lib and customised install path is installed, but system does not know that. You have to follow http://code.opencv.org/issues/1077 .

2) No shared ffmpeg

You should install ffmpeg with shared lib as other people said.

3) new ffmpeg is not "correctly" install

If new ffmpeg is built by source code and in a customise path, the path should be a absolute path. For example:

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

If a relative path is set, the relative path will be installed into ffmpeg setting file, and opencv will not find right libs according to the file. You maybe want to look into CMakeCache file in the opencv source directory, it records libs paths need in building.

like image 24
Yue Guan Avatar answered Oct 14 '22 10:10

Yue Guan