Installing from source?.. failed to build because something is missing? [Ubuntu]

Installing from source?.. failed to build because something is missing?

There is a tool (part of the apt group of tools) called apt-file that helps you find which package contains the missing file.

I was recently trying to install k3b 2.0.0 (from source files, as it isn’t available in the repos yet), the build failed… part of the output was:

CMake Error at /usr/share/cmake-2.8/Modules/FindKDE4.cmake:98 (MESSAGE): ERROR: cmake/modules/[b]FindKDE4Internal.cmake[/b] not found in /home/mark/.kde/share/apps;/usr/share/kde4/apps

I wondered how was the best way get the FindKDE4Internal.cmake file and install it.

The answer was to install apt-file:

sudo apt-get install apt-file

update its cache:

apt-file update

then search for the package that contains FindKDE4Internal.cmake:

apt-file search FindKDE4Internal.cmake

Apt-find output a single line:

kdelibs5-dev: /usr/share/kde4/apps/cmake/modules/FindKDE4Internal.cmake
(this tells you which package contains the file, and the path where it will be installed)

So the kdelibs5-dev package contained the file I needed… I installed it:

sudo apt-get install kdelibs5-dev

And the k3b 2.0.0 source files built properly.

When building from source, this is a VERY handy tool for finding missing files.

HINT: Install apt-file from the command line (not synaptic), then update its cache (again from the command line)… when I tried to install it from synaptic, it attempted to update its cache and failed with a message about not being able to start a child process.

Credit must go to this article:
http://www.linuxjournal.com/content/apt-file-locate-missing-package-files

If you find something that IS in the repos but horribly out of date (Ubuntu tend to be a year or two behind on stuff I want to use) there is another apt variant which is also very useful. Once you have acquired your source package, do;

apt-get build-dep

This will acquire all the dependant packages and libraries used to build the version of the package currently available, and whereas a newer version of the source code may well require some new libraries, this command will generally obtain most of the packages you need leaving one or two over for apt-file.