Fixing libavcodec.a linking error during build

asked 2016-01-20 13:07:49 -0600

I initially built opencv in my ~/opt/ directory with no issues, but then experienced errors using cv2.VideoCapture() via the python bindings. This SO answer led me to rebuild ffmpeg, after which I tried to rebuild opencv in my root /opt/ directory.

I got the following error, and I can't seem to figure out what is causing this. Any suggestions? Thanks for the help!

 [ 18%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o
In file included from /opt/opencv/modules/videoio/src/cap_ffmpeg.cpp:45:0:
/opt/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘bool OutputMediaStream_FFMPEG::open(const char*, int, int, double)’:
/opt/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2230:41: warning: ignoring return value of ‘int avformat_write_header(AVFormatContext*, AVDictionary**)’, declared with attribute warn_unused_result [-Wunused-result]
         avformat_write_header(oc_, NULL);
                                         ^
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.1.0] Error 1
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [all] Error 2
edit retag flag offensive close merge delete

Comments

You are trying to mix up 32bit and 64bit systems/libraries?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-01-21 04:40:39 -0600 )edit

Hmmm... not intentionally. I will take a look at that. Thank you Steven.

ryanjdillon gravatar imageryanjdillon ( 2016-01-21 04:42:28 -0600 )edit

It seems it has to do with the Makefile not using the -fPIC flag, as the error suggests. This SO question discusses this.

ryanjdillon gravatar imageryanjdillon ( 2016-01-21 04:50:27 -0600 )edit

O you are building static libraries :D is there a reason why you dont use the shared libraries?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-01-21 05:48:19 -0600 )edit

From that SO answer I listed, it mentioned recompiling ffmpeg. I did this with the suggested codec libraries from the ffmpeg page, altering nothing from the code pastes the provided. I guess I'm not sure how to explicitly build from static or shared libraries. Any suggestions?

ryanjdillon gravatar imageryanjdillon ( 2016-01-21 05:52:34 -0600 )edit