How to integrate libav* libraries to a UE project

Hello. I am trying to use libav* libraries to encode and compress scenes captured from the game and send them to the clients connected to it. To be more specific, I am working on enhancing the Carla Simulator to allow cameras to send compressed video streams instead of raw RGB images to clients, as raw RGB data takes too much network bandwidth and makes remote connection unrealistic.

Here is a list of what I have done so far:

  1. Get libraries from the official repo: https://github.com/libav/libav.git
  2. Compile with CFLAGS=“-fPIC” (Since libav* is pure C, there is no CXXFLAGS to be set)
  3. Move header files under Plugins/CarlaDependencies/include and move static library files (.a) under Plugins/CarlaDependencies/lib
  4. In the corresponding Build.cs file add PublicAdditionalLibraries.Add(Path.Combine(LibCarlaInstallPath, "lib", "libavcodec.a")); (and other lib files as well)

However, when I recompile the project, it throws this error:

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol ff_pb_80; recompile with -fPIC
>>> defined in <project_path>/carla/Unreal/CarlaUE4/Plugins/Carla/CarlaDependencies/lib/libavcodec.a(constants.o)
>>> referenced by idctdsp_mmx.c:115 (libavcodec/x86/idctdsp_mmx.c:115)
>>>               idctdsp_mmx.o:(ff_put_signed_pixels_clamped_mmx) in archive <project_path>/carla/Unreal/CarlaUE4/Plugins/Carla/CarlaDependencies/lib/libavcodec.a

but libav* is already compiled with -fPIC. Does anyone know how to correctly use libav* in UE projects?

Environment:

How are you compiling the library? Are you certain the -fPIC is applied?