Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange linker error while compiling OpenCV2.3.1 on Ubuntu 11.10

I'm trying to compile OpenCV version 2.3.1 on an Ubuntu 11.10 following instructions described here. I'm getting following error. Can't understand what is happening... /usr/local/lib/libavcodec.a exists but linker can't link against it, or something else?

error:

[ 20%] Built target pch_Generate_opencv_highgui
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet' 
can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
like image 264
sorush-r Avatar asked Dec 03 '11 18:12

sorush-r


2 Answers

The problem is that you are attempting to link libopencv_highgui.so with libavcodec.a. The latter is built from code compiled without -fPIC (which is quite usual), and such code can not be linked into shared libraries on x86_64.

Your choices are:

  • Obtain libavcodec.so and arrange to link against it, or
  • Remove libavcodec or -lavcodec from the link line completely.

For the first, you most likely just need to install libavcodec-dev package.

If you do the second, you will still have to arrange for symbols that libopencv_highgui.so needs from libavcodec to be available at runtime. You can achieve that by linking the main executable with libavcodec (either archive or shared variant).

like image 114
Employed Russian Avatar answered Oct 06 '22 01:10

Employed Russian


my take would be that, first run sudo apt-get remove libavcodec , then re-install with sudo apt-get install libopencv-dev

I once had similar issue, and the above resolved it

like image 25
Damilola Avatar answered Oct 05 '22 23:10

Damilola