如何在没有 PIE 的情况下编译 FFMPEG 和 Libaom

如何在没有 PIE 的情况下编译 FFMPEG 和 Libaom

我正在尝试从源代码编译 FFMPEG 和 Libaom,显然是因为 Ubuntu 18.04 中的 gcc 和 g++ 编译器默认启用了以下选项:--enable-default-pie

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-16ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --with-as=/usr/bin/x86_64-linux-gnu-as --with-ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)

我尝试过通过,--extra-ldexeflags="-no-pie -fno-pic -fno-pie"但没有帮助。尝试编译 libaom 时也遇到了同样的问题。我尝试安装旧版本的 gcc,但即使是 5.X 也--enable-default-pie默认启用了此选项,所以不太好。显然,此选项已在 Ubuntu 18.04 上强制使用,没有办法解决。

这是我尝试安装 libaom 时出现的错误:

64%] Linking CXX executable examples/decode_with_drops
/usr/bin/x86_64-linux-gnu-ld: libaom.a(fwd_txfm_ssse3_x86_64.asm.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: libaom.a(quantize_ssse3_x86_64.asm.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: libaom.a(subpel_variance_sse2.asm.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: libaom.a(highbd_subpel_variance_impl_sse2.asm.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
CMakeFiles/decode_with_drops.dir/build.make:155: recipe for target 'examples/decode_with_drops' failed
make[2]: *** [examples/decode_with_drops] Error 1
CMakeFiles/Makefile2:936: recipe for target 'CMakeFiles/decode_with_drops.dir/all' failed
make[1]: *** [CMakeFiles/decode_with_drops.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

[编辑]:添加我的 ffmpeg 编译命令。

我遵循了 Ubuntu 编译指南,但我的命令有点不同。我已禁用 ffplay,因为我正在服务器上安装 ffmpeg 并启用了 libsrt(Haivision 安全可靠传输协议)和 libaom(AV1)。我还更改了下载链接以下载稳定的 4.0 版本,而不是最新的夜间版本。这是我的 ffmpeg 编译命令:

cd ~/ffmpeg_sources && \
wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-4.0.tar.bz2 && \
tar xjvf ffmpeg-snapshot.tar.bz2 && \
cd ffmpeg-4.0 && \
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --extra-libs="-lpthread -lm" \
  --bindir="$HOME/bin" \
  --enable-shared \
  --enable-gpl \
  --enable-nonfree \
  --enable-ladspa \
  --enable-libsrt \
  --enable-libsoxr \
  --enable-libspeex \
  --enable-avfilter \
  --enable-avresample \
  --enable-postproc \
  --enable-pthreads \
  --enable-libfdk-aac \
  --enable-libopus \
  --enable-libass \
  --enable-libtheora \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-libfreetype \
  --enable-libkvazaar \
  --disable-ffplay \
  --enable-libopenjpeg \
  --enable-libwebp \
  --enable-libxvid \
  --enable-libvidstab \
  --enable-libopenh264 \
  --enable-zlib \
  --enable-openssl && \
PATH="$HOME/bin:$PATH" make -j8 && \
sudo make install && \
hash -r

答案1

我更新了您所遵循的指南,以包含 libaom 编译说明,而无需安装其他指南gcc或处理任何 PIE 问题:

cd ~/ffmpeg_sources && \
git -C aom pull 2> /dev/null || git clone --depth 1 https://aomedia.googlesource.com/aom && \
mkdir aom_build && \
cd aom_build && \
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off -DENABLE_NASM=on ../aom && \
PATH="$HOME/bin:$PATH" make && \
make install

这些说明可能会发生变化。请始终参考FFmpeg Wiki:针对 Ubuntu 进行编译以获取最新说明。

然后ffmpeg按照指南所示进行编译。

答案2

因此问题在于 gcc7 编译器是内置的,因此解决方案要么是使用和标志--enable-default-pie重新编译 gcc ,要么安装不支持 pie 的版本。正如 Knud Larsen 建议的那样,我安装了 gcc-5.4.0 并链接了 gcc 和 g++ 以指向此版本:-no-pie-fno-pie

sudo rm /usr/bin/gcc /usr/bin/g++
sudo ln -s /usr/bin/gcc54 /usr/bin/gcc
sudo ln -s /usr/bin/g++54 /usr/bin/g++

然后在编译文件夹中执行

make clean 
make distclean 

然后重新编译 ffmpeg,这解决了我的问题。完成后,一个好主意是重新链接您的gccg++到您安装的最新版本,在我的情况下是 7。

相关内容