1

When compiling a source package, I got an error from make that looked like:

In file included from foo.c:28:0:
bar.h:23:18: fatal error: bar.h: No such file or directory
 #include <bar.h>    
               ^
compilation terminated.
make[x]: *** [baz] Error 1
make[x]: Leaving directory 

How do I handle this?

1 Answer 1

2

This typically indicates that you haven't installed some dependency of the program you are trying to compile. Depending on the header file in question and the program you are trying to compile, you have a couple of options:

Target software exists in the Ubuntu repositories

Sometimes you want to compile from source a package already provided by Ubuntu (to get a different version, perhaps, or to patch it). If the software hasn't changed too much, you can use apt to get the dependencies:

sudo apt-get build-dep <package-name>

This should install all the packages needed to build the Ubuntu package of that software (which may have fewer or more packages than what your source package actually needs).

If you only need to make some minor change in the source, or apply a patch, you might even be able to save a significant bit of effort by letting apt and dpkg do the legwork:

sudo apt-get build-dep <package-name>
apt-get source <package-name>

This will download the source files of the package, including everything needed to make a package of it. The files will be in a directory named <package-name>-<some-version>. Enter it, make all the changes you want, and then do:

sudo dpkg-buildpackage -b -us -uc

This creates unsigned binary package(s) in the parent directory (cd ..). You can then use dpkg to install these packages:

sudo dpkg -i  <package-name>_<some-version>_<architecture>.deb

Examples:

  1. Changing one build option in a package
  2. Can't edit plugins/sudoers/ins_*.h

Target software is not present in the Ubuntu repositories

You can still try your luck with the specific header file missing. Use either the Ubuntu Packages index (the option to search the contents of packages) or apt-file to search for the file. Sometimes multiple packages may provide similarly named files, in which case, prefer:

  1. Files in /usr/include.
  2. Packages of your architecture (use uname -m to know what your architecture is).
  3. Any specific versions your software depends on (such as Qt4 instead of Qt5) - check the README and INSTALL files in the source (if present).
  4. Packages whose names end in -dev, which typically include headers needed for compiling.

See: How do I find the package that provides a file?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .