How do I compile FFMPEG & Libaom without PIE

3

I am trying to compile FFMPEG and Libaom from source apparently because the gcc and g++ compilers in Ubuntu 18.04 by default has enabled the following option by default: --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)

I have tried to pass an --extra-ldexeflags="-no-pie -fno-pic -fno-pie"but it didn't help. I have the same problem when trying to compile libaom. I have tried to install an older version of gcc but even 5.X has this --enable-default-pie option enabled by default, so it is not good. Apparently this option has been forced on Ubuntu 18.04 and there is no way around it.

That's my error while trying to install 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

[EDIT]: Adding my ffmpeg compilation command.

I was following the Ubuntu compilation guide posted at My command was a bit different though. I have disabled the ffplay, since I am installing ffmpeg on a server and enabled libsrt (Haivision Secure Reliable Transport Protocol) and libaom (AV1). I have also changed the download link to download the stable 4.0 version instead of the latest nightly build. This is my ffmpeg compilation command:

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

Georgе Stoyanov

Posted 2018-05-07T11:32:14.900

Reputation: 290

I'd say this belongs to StackOverflow. Compiling ffmpeg is requires arcane knowledge anyway. – None – 2018-05-07T11:35:45.150

any idea, how I can move it from here to there? When I tried to create a new thread on Stackoverflow, it said that I can post only post once every 90 minutes. – Georgе Stoyanov – 2018-05-07T11:42:47.460

I flagged it for transfer. So, just wait. – None – 2018-05-07T11:46:25.073

2

If you're asking in order to compile the program as a user and not a developer, this doesn't need to be migrated. That said, it might be useful if you (a) change the title of the question to e.g. "how do I compile FFMPEG without PIE?", and (b) explain why you need PIE disabled. Perhaps there is an alternative solution.

– Bob – 2018-05-07T14:00:36.987

PIE is default in gcc v.5.5, not in 5.4 . ... You can use the new "no-pie" gcc54-c++_5.4.0-ubuntu16_amd64.deb for 18.04 (and 16.04) https://drive.google.com/file/d/1ptHLaZXImpeMzq4xuuGGn5VjrvxNSop3/view?usp=sharing ... Provides /usr/bin/{gcc54, g++54, gfortran54} . Install : sudo gdebi Downloads/gcc54-c++_5.4.0-ubuntu16_amd64.deb

– Knud Larsen – 2018-05-07T15:25:26.030

Works for me in 18.04. Show your cmake command or whatever info is needed to duplicate the issue. – llogan – 2018-05-07T22:26:46.800

Thanks to @KnudLarsen I was able to compile successfully ffmpeg and libaom. I have also changed the title as "alternative solution" suggested. – Georgе Stoyanov – 2018-05-08T12:47:51.183

I did not have to use the PIE-less gcc to compile: I should clarify that's what I meant when I said it "works for me". I wanted to resolve your specific issue first before providing compile instructions (it's why I asked for the commands you used so I could replicate your issue). If you found a solution you can also add it as an answer. – llogan – 2018-05-08T16:35:33.767

Answers

3

I updated the guide you followed to include libaom compilation instructions without needing to install another gcc or deal any PIE issues:

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

These instructions are liable to change. Always refer to FFmpeg Wiki: Compiling for Ubuntu for up to date instructions.

Then compile ffmpeg as shown in the guide.

llogan

Posted 2018-05-07T11:32:14.900

Reputation: 31 929

By the way, when I am using the libaom command you have put into the FFmpeg Wiki: Compiling for Ubuntu I get an error: error: ‘AV1_COMMON {aka struct AV1Common}’ has no member named ‘enhancement_layers_cnt’ operating_point >= pbi->common.enhancement_layers_cnt.

– Georgе Stoyanov – 2018-05-15T15:13:58.630

@GeorgеStoyanov I can't duplicate that error (or I missed it). Which step in the instructions give you that message? Is it a fatal error? – llogan – 2018-05-16T20:38:13.790

1

So the problem was that the gcc7 compiler was coming with built-in --enable-default-pie so the solution was either to recompile the gcc with -no-pie and -fno-pie flags or install a version without the pie support. As Knud Larsen suggested I have installed gcc-5.4.0 and linked gcc and g++ to point to this version:

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++

and then executed in the compilation folder

make clean 
make distclean 

and recompiled again ffmpeg and this solved my issue. A good idea after you finish is to re-link your gcc and g++ to the most recent version you have installed, in my case that was 7.

Georgе Stoyanov

Posted 2018-05-07T11:32:14.900

Reputation: 290