LHAPDF is hosted by Hepforge, IPPP Durham
LHAPDF  6.1.6
Installation instructions

Source file downloads

The source files can be downloaded from https://www.hepforge.org/downloads/lhapdf

Quick start instructions

If you have a C++ compiler and the Boost C++ library+headers installed in system paths, building LHAPDF should be straightforward:

wget http://www.hepforge.org/archive/lhapdf/LHAPDF-6.X.Y.tar.gz
tar xf LHAPDF-6.X.Y.tar.gz
./configure --prefix=/path/for/installation
make install

You will then need to install PDF data files, most easily using the "lhapdf" manager script but also possible by manual download. See the LHAPDF website for details.

On systems where you want to use non-system compilers and libraries, the configure command will need to be a bit more complicated: see the following for more information.

Build tools

LHAPDF6 just needs your system to have a copy of Make and a C++ compiler: there is no Fortran code and hence no need for gfortran. We have tested with both the g++ and clang++ compilers and LHAPDF6 compiles with all known versions.

Building LHAPDF is typically straightforward on Linux systems, including SLC6 and Ubuntu. Mac OS X, however, can cause problems due to inconsistent compiler and Python versions, and other such fun. If you want to build LHAPDF on a Mac, please see Building on Mac OS X.

External dependencies


LHAPDF6 makes use of header files from the Boost C++ utility library (http://www.boost.org). On Linux machines this should typically be available via your system's packaging mechanism, e.g. the libboost-all-dev package on Ubuntu and other Debian derivatives. On Scientific Linux 6 the system installation of Boost is sufficient for LHAPDF 6.0.5 and later. By comparison, the system copy on SL5 is too old, but surely everyone has upgraded to v6 by now...

Building Boost by hand is not particularly simple and should not be needed in most cases: we recommend avoiding this! If you have access to the CERN AFS filesystem, you can find builds of Boost for various platforms in the /afs/cern.ch/sw/lcg/external/Boost/ directory. If you really want or need to do it manually, version 6.0.5 and later of LHAPDF only use Boost headers (previous ones used compiled libraries) and rather than fully building Boost, you can just use the header files direct from its source tarball: this is not wonderfully neat, but is a lot easier than doing a full manual build and installation of the Boost libraries.


If you want to build the Python interface to LHAPDF (which is very nice!), you will need the Python development headers to be installed (e.g. via the python-dev Ubuntu package). If the Python.h header is not found by configure, no Python extension module will be built.

Building LHAPDF

If you have downloaded a release tarball for LHAPDF 6.X.Y, unpack it with tar xf LHAPDF-6.X.Y.tar.gz, then cd to the newly-created directory.

If checking out from version control rather than unpacking a tarball, again cd to the new directory, but you must then also run autoreconf -i before proceeding to the instructions below. There will also be more requirements for external packages if you build this way, since this is the "developer" route to building LHAPDF and requires a bit more expertise.

Now you should run the configure script to analyse your machine, compiler, etc. and set up the Makefiles. You will probably need to provide the --prefix argument to configure to tell it where you want to install LHAPDF (probably you don't want to install to /usr/local, which is the default) and perhaps use the --with-boost flag to indicate the locations of your Boost installation. For example,

./configure --prefix=$HOME/local

should be appropriate if you have installed Boost in /usr via your machine's packaging system. If not, you will need something like

./configure --prefix=$HOME/local --with-boost=$HOME/pkgs/boost-1_58

The --prefix, --with-boost, etc. path flags expect the "base" location of the package, e.g. if you have installed library X such that there are headers in /foo/include/ (or /foo/include/X) and a compiled library (or libraries) in /foo/lib/ then you would use --with-X=/foo.

An example build script for LHAPDF6 on the CERN lxplus6 system is shown at the end of these instructions.

Alternative compilers

If you want to use an alternative C++ compiler, then you can specify the CXX variable on the command line. This is essential on OS X Mavericks and later, where the consistent compiler suite is clang rather than gcc – in that situation, use:

./configure --prefix=... CC=clang CXX=clang++

The configure script will run and produce quite a bit of output from its various tests. Hopefully everything will be successful: if it gets to the end without stopping due to an error then all is well.

Then just call make to build the library (or e.g. make -j4 to compile 4 files in parallel – if your machine has enough processor cores to do so, even -j2 will speed up the build quite a bit). To install LHAPDF to the --prefix location that you specified, call make install. You will (or at least should(!) find installed files in $prefix/lib, $prefix/include/LHAPDF, and $prefix/share/LHAPDF.

Building on lxplus

CERN's lxplus shared system is always an awkward environment to build packages, since the system compiler etc. are not part of the LCG supported list of architectures. Here is an example of how to build LHAPDF and its dependencies on lxplus6 – although you can of course use other compilers, Python versions, build flags, etc. as you wish.

## Set up LCG build tools (optional)
#source /cvmfs/sft.cern.ch/lcg/releases/LCG_87/gcc/4.9.3/x86_64-slc6/setup.sh
#export BOOST_ROOT=/cvmfs/sft.cern.ch/lcg/releases/LCG_87/Boost/1.62.0/x86_64-slc6-gcc49-opt

## Make an install directory
mkdir local

## Build LHAPDF
wget http://www.hepforge.org/archive/lhapdf/LHAPDF-6.X.Y.tar.gz -O- | tar xz
./configure --prefix=$PWD/../local
make -j2 && make install
cd ..

## Set environment variables
export PATH=$PWD/local/bin:$PATH
export PYTHONPATH=$PWD/local/lib64/python2.6/site-packages:$PYTHONPATH

## Test the scripts
lhapdf-config --help
lhapdf list

Building on Mac OS X

Builds are typically straightforward on Linux, but Mac OS X unfortunately has a long history of incoherent system compiler setups, which have been worked around manually by users' private installations of Fink, MacPorts, HomeBrew and manual tarball installations of required tools. These work-arounds can themselves be the source of problems when the native compilers or Python libraries get updated, and due to the ad hoc nature of such installations we are restricted in how much we can help to get LHAPDF to compile on a broken system: it is the user's responsibility to make sure that their machine has a consistent set of build tools!

From experience, the simplest reliable route seems to be to run a fresh copy of OS X 10.9 Mavericks (or later) without any additional manual compiler installations: if you use the clang++ compiler on such a system, LHAPDF6 building should "just work".

At the time of writing there is a bug in the Mac Python version which requires that you call export CPPFLAGS=-Qunused-arguments and export CFLAGS=-Qunused-arguments before building. Alternatively you can run the configure script with --disable-python, which avoids the bug at the cost of not building the very useful Python interface to LHAPDF.

The Mac OS X "Homebrew" system (http://brew.sh/) comes recommended by several LHAPDF developers. Many HEP packages are already available for Homebrew via the homebrew-hep project: http://davidchall.github.io/homebrew-hep/ . Success has also been reported with the MacPorts system (http://www.macports.org/): please see HepForge's information about MacPorts at https://www.hepforge.org/docs/macosx . With both these approaches, you should set your environment to only use compilers and Python from the Brew/Ports area and to ignore the system packages: a hybrid approach will only cause unnecessary pain.