mattgadient.com

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!

7 Comments

 | Leave a Comment Sort by Oldest | Sort by Newest
  1. 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. Thank you very much. Nice post. 1: Errors in m4 solved my problem. Can I buy a bear? 🙂

  3. Hot Dang

    Fixing that m4 file up lets me compile Handbrake on Debian Jessie.

  4. Manuel Riel

    Priceless post. Fixed my m4 issues as well.

  5. 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.

    • 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!

    • 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

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.

To reduce spam, I manually approve all comments, so don't panic if your comment doesn't show up immediately.