如何处理“重新使用 -fPIC 重新编译”的消息

我正在尝试配置ffmpeg源代码包,以构建.so文件而不是.a文件。
在执行了"./configure --enable-shared"之后,我运行了"make"命令。
这给我返回了以下信息:
"/usr/bin/ld: libavutil/display.o: relocation R_X86_64_PC32 against undefined symbol 'hypot@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC"
然而,我不确定在哪里以及如何添加-fPIC标志。

.so文件是Ubuntu的标准。在哪些(二进制)软件包中找不到.so文件? - saiarcot895
3个回答

有一个./configure选项可能是解决这个问题最简单的方法:
andrew@ilium~/source/ffmpeg_build/ffmpeg/ffmpeg$ ./configure --help | grep -i pic
--enable-pic             build position-independent code

我已经解决了在Ubuntu 14.04 LTS上编译FFMpeg 2.3.3源代码时出现的相同错误。在将LD_LIBRARY_PATH设置为/usr/lib/x86_64-linux-gnu并且在--cc后添加了-fPIC标志之后,成功地编译了代码。我的工作编译命令如下:
LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
./configure --prefix=.. --enable-shared --enable-gpl --enable-version3 --enable-runtime-cpudetect --disable-outdev=sdl --disable-opencl --enable-libmp3lame --enable-libx264 --cc="gcc -m64 -fPIC" --extra-cflags="-I../include" --extra-ldflags="-L../lib -ldl"
make -j4

不要忘记在添加-fPIC标志后进行清理工作。 - user370852

当LDFLAGS设置为硬化并且CFLAGS没有设置时,通常会发生对未定义符号的重定位R_X86_64_PC32。
可能只是用户错误:
如果在链接时使用了-specs=/usr/lib/rpm/redhat/redhat-hardened-ld, 那么在编译时也需要使用-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1,并且由于您同时进行编译和链接,所以需要两者都有,或者去掉-specs=/usr/lib/rpm/redhat/redhat-hardened-ld。 常见修复方法:
https://bugzilla.redhat.com/show_bug.cgi?id=1304277#c3
https://github.com/rpmfusion/lxdream/blob/master/lxdream-0.9.1-implicit.patch