Working around hiccups when compiling Handbrake on Linux

Throwing this here primarily for my own benefit (easier than sifting through my local text files of notes), but perhaps this will benefit someone else too.

Basically, each time I’d go to compile HandBrake in Ubuntu, I’d hit a new error. Listing them (and the resolutions) here.

At the very end I’ll list my script for “fresh” Ubuntu installs that:

  1. Grabs dependencies.
  2. Clones HandBrake from git.
  3. Manually (replaces) the M4 file and sets environment variables.
  4. Compiles HB.
  5. …(usually) avoids hitting any errors in the process.

But first… dealing with the errors on a case-by-case basis!
Handbrake m4 issue - stdio.h:477:1: error: 'gets' undeclared here (not in a funciton)

1: Errors in m4

stdio.h:477:1: error: ‘gets’ undeclared here (not in a function) 

HB currently pulls GNU m4-1.4.16 which recent compilers will fail. There’s a newer version of m4 that won’t trigger this issue. Easiest way to get it is to edit ./contrib/m4/module.defs and replace with the following:

$(eval $(call import.MODULE.defs,M4,m4))
$(eval $(call import.CONTRIB.defs,M4))

M4.FETCH.url = http://ftp.gnu.org/gnu/m4/m4-1.4.17.tar.bz2
M4.FETCH.md5 = 8a1787edcba75ae5cd1dc40d7d8ed03a

…this tells HandBrake to grab 1.4.17

2: libmp3lame , libass-dev , and libsamplerate-dev dependencies missing

When compiling HB on Ubuntu via the guide at https://trac.handbrake.fr/wiki/CompileOnLinux , not *all* the needed dependencies are listed.

Worth noting that viewing the source and following the guide in doc/BUILD-Linux is usually a better idea than the link above, since it seems to be updated a little more frequently and has some extended info.

Identifying dependencies:

  • libmp3lame-dev is fairly easy to identify if missing
  • libass-dev is needed if you get “fatal error: ass/ass.h: No such file or directory”
  • libsamplerate-dev is needed if you get “fatal error: samplerate.h: No such file or directory”

Anyway, to install them on Ubuntu:

apt-get install libmp3lame-dev
apt-get install libass-dev
apt-get install libsamplerate-dev

..another one down!

3: libxml2/pkgconfig issues

They happen when trying to configure libbluray, and errors look like this:

: checking pkg-config is at least version 0.9.0… yes
: checking for LIBXML2… no
: configure: error: Package requirements (libxml-2.0 >= 2.6) were not met:
:
: No package ‘libxml-2.0’ found
:
: Consider adjusting the PKG_CONFIG_PATH environment variable if you
: installed software in a non-standard prefix.
:
: Alternatively, you may set the environment variables LIBXML2_CFLAGS
: and LIBXML2_LIBS to avoid the need to call pkg-config.
: See the pkg-config man page for more details.
: ../contrib/libbluray/module.rules:2: recipe for target ‘contrib/libbluray/.stamp.configure’ failed
: make: *** [contrib/libbluray/.stamp.configure] Error 1

I run ldconfig…not positive if this must be done (or is at all relevant), but came across it somewhere, and it shouldn’t hurt:

ldconfig

I then export the PKG_CONFIG and PKG_CONFIG_PATH variables. This is probably the most critical part:

export PKG_CONFIG=/usr/bin/pkg-config
export PKG_CONFIG_PATH=/usr/lib/pkgconfig

If not positive where the path for the above is (could be different on different OS’s), you can verify with:

whereis pkgconfig
whereis pkg-config

node that pkgconfig will show a couple locations, but the one in the export line above is generally the correct one to use as long as it exists

 

Alternate pkg-config (usually skip this unless above didn’t work on it’s own)

If the above doesn’t work, you *could* try installing building pkg-config from source.

wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.1.tar.gz
tar xvfz pkg-config-0.29.1.tar.gz 
cd pkg-config-0.29.1/
./configure
make && make install

…that installs it, but you may have to change the pkg-config path. Not positive here because this is where things usually start to fall apart for me when I go this route and when I *do* eventually get it going, I’m never sure what combination of changes were responsible since I’ve impatiently changed multiple things each attempt. Anyway…

First, find the proper pkgconfig directory. To keep pages of results from showing up, I usually do it by looking for one of the files inside on the file system (zlib.pc):

updatedb
locate zlib.pc

Result is usually something like:
/usr/lib/x86_64-linux-gnu/pkgconfig/zlib.pc

Copy the colored part of the result (the path) with CTRL-C and change the PKG_CONFIG_PATH (from previous) to the following:

PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig

Replace the path with the actual path you found above (match up the blue).

 

4: Note

If after #3 you get to the point where it throws a new message during the libbluray compile about not finding libxml/parser.h, you may have to play with things a bit… I’ve only had this happen when building pkgconfig from source, so perhaps try reverting to the system’s default instead.

If you’re really fighting with libbluray, rather than cleaning the whole build and going through the entire compile again each time, you might find it easier to enter the build directory and *just* build libbluray:

./configure --whatever-options-you-are-using --but-not-the--launch-option
cd build
make libbluray

…to just do certain components, read the instructions in ./doc . For example, you can do “make libbluray.configure” and “make libbluray.build” at the correct points to do things step by step: doc/BUILD-Linux has the full details here.

Usually things work mostly-fine at this point, aside from a dependency here or there depending on the Ubuntu base install.

Note that there’s probably a really simple solution to the PKGCONFIG stuff that I missed, but it’s so late in the compile process that instead of careful trial-and-error, I’d usually try a few things at a time until I got things working.

I’ll end with the script, but if you’ve got a simpler process for working things out that might help others, feel free to leave a comment further below!

 

5: Download/compile script for fresh Ubuntu installs!

Warning: I often make little edits to these and copy/paste around, so certain portions of this could have typos and whatnot. If that wasn’t bad enough, various WordPress & database changes like to break stuff periodically (switch ‘ to ` or – – to – to <hr> etc), so be on the lookout and leave a comment if something looks like it got trashed/garbled. Use at your own risk. YMMV.

Warning #2: The 4x lines that start with “echo” might break after a HandBrake update some time in the future. If HandBrake updates to a newer version of m4, they won’t be needed anymore.

This is the mess of “everything” that I can simply copy/paste into a terminal window after a fresh Ubuntu install. Hit <enter>, come back some time later, and a freshly compiled HandBrake is (usually) waiting for me. (Oct 8 2016 Update: added libopus-dev. Thank you to Ernst and Fenris in the comments below.)

Ubuntu 16.04

apt-get update &&
apt-get install -y git cmake yasm build-essential autoconf libtool \
zlib1g-dev libbz2-dev libogg-dev libtheora-dev libvorbis-dev \
libsamplerate-dev libxml2-dev libfribidi-dev libfreetype6-dev \
libfontconfig1-dev libass-dev libmp3lame-dev libx264-dev libjansson-dev \
intltool libglib2.0-dev libdbus-glib-1-dev libgtk-3-dev libgudev-1.0-dev \
libwebkitgtk-3.0-dev libnotify-dev libgstreamer1.0-dev libopus-dev \
libgstreamer-plugins-base1.0-dev libappindicator-dev libtool-bin &&
apt-get install -y libmp3lame-dev libass-dev libsamplerate-dev &&
ldconfig &&
export PKG_CONFIG=/usr/bin/pkg-config &&
export PKG_CONFIG_PATH=/usr/lib/pkgconfig &&
git clone https://github.com/HandBrake/HandBrake.git hb-master &&
cp -n ./hb-master/contrib/m4/module.defs ./hb-master/contrib/m4/module.defs.bak &&
echo '$(eval $(call import.MODULE.defs,M4,m4))' > ./hb-master/contrib/m4/module.defs &&
echo '$(eval $(call import.CONTRIB.defs,M4))' >> ./hb-master/contrib/m4/module.defs &&
echo 'M4.FETCH.url = http://ftp.gnu.org/gnu/m4/m4-1.4.17.tar.bz2' >> ./hb-master/contrib/m4/module.defs &&
echo 'M4.FETCH.md5 = 8a1787edcba75ae5cd1dc40d7d8ed03a' >> ./hb-master/contrib/m4/module.defs &&
cd hb-master &&
./configure --disable-gtk &&
cd build &&
make

Ubuntu 14.04 (likely also 15.10, 15.04, 14.10, and possibly older stuff)

apt-get update &&
apt-get install -y git cmake yasm build-essential autoconf libtool \
zlib1g-dev libbz2-dev libogg-dev libtheora-dev libvorbis-dev \
libsamplerate-dev libxml2-dev libfribidi-dev libfreetype6-dev \
libfontconfig1-dev libass-dev libmp3lame-dev libx264-dev libjansson-dev \
intltool libglib2.0-dev libdbus-glib-1-dev libgtk-3-dev libgudev-1.0-dev \
libwebkitgtk-3.0-dev libnotify-dev libgstreamer1.0-dev libopus-dev \
libgstreamer-plugins-base1.0-dev libappindicator-dev &&
apt-get install -y libmp3lame-dev libass-dev libsamplerate-dev &&
ldconfig &&
export PKG_CONFIG=/usr/bin/pkg-config &&
export PKG_CONFIG_PATH=/usr/lib/pkgconfig &&
git clone https://github.com/HandBrake/HandBrake.git hb-master &&
cp -n ./hb-master/contrib/m4/module.defs ./hb-master/contrib/m4/module.defs.bak &&
echo '$(eval $(call import.MODULE.defs,M4,m4))' > ./hb-master/contrib/m4/module.defs &&
echo '$(eval $(call import.CONTRIB.defs,M4))' >> ./hb-master/contrib/m4/module.defs &&
echo 'M4.FETCH.url = http://ftp.gnu.org/gnu/m4/m4-1.4.17.tar.bz2' >> ./hb-master/contrib/m4/module.defs &&
echo 'M4.FETCH.md5 = 8a1787edcba75ae5cd1dc40d7d8ed03a' >> ./hb-master/contrib/m4/module.defs &&
cd hb-master &&
./configure --disable-gtk &&
cd build &&
make

You could turn them into a #!/bin/bash script, but I usually just copy-paste the thing into a terminal window / ssh prompt.

Leave comments if it’s broke!

15 Comments | Leave a Comment

 Sort by Oldest | Sort by Newest
  1. Brian on July 1, 2016 - click here to reply
    Excellent work, thank you. I'm attempting to update my cross-platform benchmark and ran into new problems with handbrake. This may get me through it. At least, it solved the m4 problem.
  2. Marcel on July 1, 2016 - click here to reply
    Thank you very much. Nice post. 1: Errors in m4 solved my problem. Can I buy a bear? :)
  3. Richard on August 2, 2016 - click here to reply
    Hot Dang

    Fixing that m4 file up lets me compile Handbrake on Debian Jessie.
  4. Manuel Riel on August 24, 2016 - click here to reply
    Priceless post. Fixed my m4 issues as well.
  5. Ernst on October 7, 2016 - click here to reply
    Hi, after compiling (also after removing --disable-gtk), I don't see the gui executable. Do
    I have to add another command?

    Btw, you have to add libopus-dev om 16.04 to make it compile.
    • Matt Gadient on October 7, 2016 - click here to reply
      Hey Ernst,

      Been awhile since I built the GUI version. I believe the GUI executable might simply be called "ghb", so it's worth doing a quick search for it in some of the directories after the build takes place. I don't recall there being anything extra/special that I had to do (aside from omitting --disable-gtk and some standard dependancy hunting), but of course my memory might not be perfectly accurate here.

      As to the libopus-dev, I believe I got away without it at one point, but sure enough it's listed in https://github.com/HandBrake/HandBrake/blob/master/doc/BUILD-Linux so could certainly be required. There are a few extra GUI-specific dependencies listed there as well so if you're not getting the GUI executable (despite removing --disable-gtk), it may be worth double checking to ensure a missing dependency isn't the culprit. Good luck!
    • Fenris on October 8, 2016 - click here to reply
      Wanted to post and say thanks for a great little page, I ran into the m4 problem and found this extremely helpful.

      I needed to add the Opus dev package on Ubuntu 14.04 as well, posting the error in case it helps someone find this page:

      ERROR: opus not found

      If you think configure made a mistake, make sure you are using the latest
      version from Git. If the latest version fails, report the problem to the
      libav-tools@libav.org mailing list or IRC #libav on irc.freenode.net.
      Include the log file "config.log" produced by configure as this will help
      solving the problem.
      make: *** [contrib/ffmpeg/.stamp.configure] Error 1

      Solution:

      apt-get install libopus-dev
  6. Mike on January 4, 2018 - click here to reply
    Thanks for the post. For me its close, but not quite there. I'm trying to build on Armbian/Ubuntu 16 and there is something about the ARM architecture that it tripping up the build.

    The message I get is :
    [ 1%] Building CXX object common/CMakeFiles/common.dir/arm/asm-primitives.cpp.o
    In file included from /home/mike/hb-master/build/contrib/x265/x265_v2.6/source/common/primitives.h:34:0,
    from /home/mike/hb-master/build/contrib/x265/x265_v2.6/source/common/arm/asm-primitives.cpp:28:
    /home/mike/hb-master/build/contrib/x265/x265_v2.6/source/common/arm/asm-primitives.cpp: In function ‘void x265_10bit::setupAssemblyPrimitives(x265_10bit::EncoderPrimitives&, int)’:
    :0:9: error: ‘x265_10bit_ssim_4x4x2_core_neon’ was not declared in this scope
    /home/mike/hb-master/build/contrib/x265/x265_v2.6/source/common/cpu.h:31:28: note: in definition of macro ‘PFX3’
    #define PFX3(prefix, name) prefix ## _ ## name

    Followed by what looks like a few hundred more of a similar nature.

    Any thoughts?
    • Matt Gadient on January 4, 2018 - click here to reply
      Hey Mike,

      It might be worth peaking through the ARM-specific settings I used in my ARM writeup at https://mattgadient.com/handbrake-0-10-5-nightly-and-arm-armv7-short-benchmark-and-how-to/ . You may have to modify the module.def files for x264 and x265.

      You could try plugging in the settings I listed there for ARMv7 (armhf), but if that doesn't work you may have to tweak something for your specific ARM chip. I'd start with the x265 module.def (since that's where your build seemed to choke) and go from there.
      • Mike on January 5, 2018 - click here to reply
        Thanks for the advice, I didn't see that you had done an arm build as well.

        Nevrtheless I still got hung up on the same file. If I understand correctly I have an ARMv7 as well (it's an ASUS Tinkerboard) one think that looks wrong to me is the _10bit_ part of the expanded macro. My hunch is to change x265_10bit in the cmake files to simply x265, that way the naming should line up. It seems like a pretty drastic change though.
        • Matt Gadient on January 6, 2018 - click here to reply
          Hey Mike, probably worth mentioning that if you don't plan to use x265 (are just using x264, VPx, etc), you can always try disabling x265 before building. Instead of:
          ./configure --disable-gtk
          ...you'd do...
          ./configure --disable-x265 --disable-gtk
          • Mike on January 6, 2018
            Yup, disabling x265 was enough to get a clean build (and you were right, I don't need it).

            Thanks for all your help.

            FWIW, it's looking like my TinkerBoard is not all that its made out to be. Pretty much anytime I put it under load it shuts down and corrupts the SD card. The pi3 may not have the cpu grunt but it seems to be more reliable.
  7. Chanduthedev on November 21, 2018 - click here to reply
    Hi, I am getting below error while compiling HandBrake source code in redhat el7 version. Could you help me on this?
    ERROR: opus not found using pkg-config
    • Matt Gadient on November 21, 2018 - click here to reply
      Fenris mentioned needing to install the opus package on Ubuntu via apt-get install libopus-dev. Not sure what the package name is in RHEL, but for Fedora it looks like it may be called opus-devel so I might start there. Maybe do a quick package search via YUM (or DNF if RHEL has moved that direction - I haven't really kept up to date with RHEL package management changes over the years).

Leave a Comment

You can use an alias and fake email. However, if you choose to use a real email, "gravatars" are supported. You can check the privacy policy for more details.