Home > Article > Backend Development > Why do I get a relocation error when compiling with ffmpeg and how can I fix it?
Recompiling with -fPIC for Shared Library Compatibility
When compiling programs using libraries, it's essential to ensure compatibility between the library type and the compilation flags. One such scenario occurs when using the ARM Ubuntu machine to reinstall ffmpeg. Compiling a program that utilizes the ffmpeg library might result in the following error:
/usr/bin/ld: /usr/local/lib/libavcodec.a(amrnbdec.o): relocation R_ARM_MOVW_ABS_NC against `a local symbol' 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
This error indicates a mismatch between the library type and the compilation flags. The -fPIC flag is typically used when compiling code that will be included in a shared library (.so). By default, however, ffmpeg is often compiled into a static library (.a).
To resolve this issue, you must recompile ffmpeg with the -fPIC flag. This can be accomplished by modifying the compilation options when configuring ffmpeg. To do so, add "--enable-shared" to the ./configure options. Alternatively, you can disable shared libraries altogether by adding "--disable-shared" instead.
Once this change is made, recompiling ffmpeg will produce a shared library (.so) instead of a static library (.a). When you compile your program that uses the ffmpeg library, it will be able to successfully link with the shared library, resolving the relocation error.
The above is the detailed content of Why do I get a relocation error when compiling with ffmpeg and how can I fix it?. For more information, please follow other related articles on the PHP Chinese website!