编译静态ffmpeg 后再应用到自编译动态库中会出现如下错误:
/usr/bin/ld: //usr/local/lib/libavcodec.a(hevc_cabac.o): relocation R_X86_64_PC32 against symbol `ff_h264_cabac_tables' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: //usr/local/lib/libavcodec.a(cavsdsp.o): relocation R_X86_64_PC32 against symbol `ff_pw_5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: //usr/local/lib/libavcodec.a(h264_cabac.o): relocation R_X86_64_PC32 against symbol `ff_h264_cabac_tables' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: //usr/local/lib/libswscale.a(swscale.o): relocation R_X86_64_PC32 against symbol `ff_M24A' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: //usr/local/lib/libswscale.a(rgb2rgb.o): relocation R_X86_64_PC32 against symbol `ff_w1111' can not be used when making a shared object; recompile with -fPIC
查找到的都是在编译 ffmpeg 的时候 需要在./configure --enable-pic --extra-cflags="-fPIC " ,但是添加后依旧会出现这些链接错误,
解决方法:
如果是qt 的工程,需要在.pro 中加入 QMAKE_LFLAGS += "-Wl,-Bsymbolic"
或者可以在cmakelist 文件中加入 set(CMAKE_SHARED_LINKER_FLAGS "-Wl, -Bsymbolic")
重新编译即可