CERNLIB build instructions for Linux (x86-64)

CERNLIB 2005 and 2006 (64 bit)
compatible with the gcc10/gfortran compiler suite


Dec 11, 2020:   new CERNLIB 2005 patches for gcc10

Again for the CERNLIB 2005 distribution, a new set of "patches" has been created, which corrects compilation issues for gcc10
The new patchset cernlib.2005.corr.2020.12.11.tgz and the new patched installation scripts cernlib.2005.install.2020.12.11.tgz, both created by Luke Pickering, are ready for download.
The main two changes are that a few gcc warnings that became errors in 10 (https://gcc.gnu.org/gcc-10/porting_to.html) So the -std=legacy was added, which gets around most of this. The other update is that the cshell one-liner for getting the gcc version assumes that it only a single character long... which now we're on 10 meant that it read it as gcc 1, causing all sorts of problems.

Feb 03, 2019:   CERNLIB 2006 on newer Linux systems

######################################################################

# On Ubuntu 18.04 / x86_64, the system provided CERNLIB 2006 and its
# executables misbehave. Most probably, the same problems appear in
# all recent distributions. Until a proper fix is found, one needs to
# make sure that all FORTRAN code is compiled with "-O" (i.e. "-O1")
# and not with the default "-O3" (even "-O2" results in misbehavior).
# Below you can find the whole procedure which applies some small
# patches to the "cernlib" source code and then rebuilds and installs
# everything from scratch. This procedure (and the patches) should be
# fine for any distribution, which uses some new Debian's "cernlib"
# source code (older versions are NOT o.k. at all with any gcc 5+):
#   cernlib_20061220+dfsg3-4.3ubuntu2
#   cernlib_20061220+dfsg3-4.3ubuntu1
#   cernlib_20061220+dfsg3-4.3build1
#   cernlib_20061220+dfsg3-4.3
# Note: if no "debuild" then "sudo apt-get install devscripts".
# Last update: 2019.02.03, Jacek M. Holeczek

rm -rf cernlib_debuild
mkdir cernlib_debuild
cd cernlib_debuild

sudo apt-get build-dep cernlib
apt-get source cernlib
cd cernlib-20061220*
# note: do NOT worry if ONE hunk fails for 102-dont-optimize-some-code.dpatch
patch -p1 < ../../cernlib-20061220+dfsg3.patches.2019.02.03.txt
debuild -us -uc > ../debuild_us_uc.cernlib.out.txt 2>&1
cd ..
rm -f cernlib-extras_*.deb pawserv_*.deb zftp_*.deb # you do NOT need them
sudo dpkg -i *.deb # note: do NOT worry about THREE "dependency problems"
sudo apt-get -y purge cernlib cernlib-core cernlib-core-dev # temporarily "out"

sudo apt-get build-dep paw
apt-get source paw
cd paw-2.14.04*
debuild -us -uc > ../debuild_us_uc.paw.out.txt 2>&1
cd ..
sudo dpkg -i *.deb # note: do NOT worry about ONE "dependency problem"
sudo apt-get -y purge cernlib # temporarily "out"

sudo apt-get build-dep cernlib-montecarlo # "cernlib-montecarlo" or "mclibs"
apt-get source cernlib-montecarlo # "cernlib-montecarlo" or "mclibs"
cd mclibs-20061220*
debuild -us -uc > ../debuild_us_uc.mclibs.out.txt 2>&1
cd ..
sudo dpkg -i *.deb # note: do NOT worry about ONE "dependency problem"
sudo apt-get -y purge cernlib # temporarily "out"

sudo apt-get build-dep geant321
apt-get source geant321
cd geant321-3.21.14*
debuild -us -uc > ../debuild_us_uc.geant321.out.txt 2>&1
cd ..
sudo dpkg -i *.deb # note: there should be NO ANY "dependency problem"

# note: make sure that they do not get "automatically" upgraded
sudo apt-mark hold `ls -1 *.deb | sed -e '{s/_.*\.deb//}'`

# note: you can purge these installed (and "held back") packages using
# sudo apt-get purge `ls -1 *.deb | sed -e '{s/_.*\.deb//}'`

######################################################################

Jan 21, 2019:   new CERNLIB 2005 patches

For people who cannot live without this CERNLIB 2005 distribution, a new set of "patches" has been created, which helps on newest systems and compilers.
The new patchset cernlib.2005.corr.2019.01.21.tgz and the new patched installation scripts cernlib.2005.install.2019.01.21.tgz, both created by Jacek M. Holeczek, are ready for download.
This new set of "patches" has been tested on several systems: CentOS 7, Ubuntu 14.04 and 18.04, and several compilers: gcc 4.8.x and 7.3.x.

Jul 23, 2014:   new CERNLIB 2005 patches

Some people insist on using this CERNLIB 2005 distribution so a new set of "patches" has been created which helps on newest systems and compilers (it includes a fix for the "freetype" problem reported below). New installation scripts will also compile and run all available test suites now.
The new patchset cernlib.2005.corr.2014.04.17.tgz and the new patched installation scripts cernlib.2005.install.2014.04.17.tgz, both created by Jacek M. Holeczek, are ready for download.
This new set of "patches" has been tested on several systems: SL(C)5, SL(C)6, CentOS 6, Ubuntu 12.04 and 14.04, Fedora 14 and 20 and several compilers: gcc 4.4.x, 4.6.x, 4.8.x.

Jul 04, 2013 (Ubuntu warning added Oct 31, 2013):   CERNLIB 2006 on newer Linux systems

Many new Linux distributions offer CERNLIB 2006 binary packages. The source code is actually maintained by the Debian Project now. However, due to licensing problems, not all original CERNLIB 2006 routines and libraries are available (and hence they are also missing in binary packages which originate in this source code). Note that Debian splits CERNLIB 2006 into four source code packages called "cernlib", "paw", "geant321" and "mclibs" (Monte Carlo libraries). They also provide a separate "cfortran" package, if you need it.

See, for example:
https://userweb.jlab.org/~marki/cernlib_on_debian/cernlib/
http://git.debian.org/?p=debian-science/packages/cernlib.git
http://git.debian.org/?p=debian-science/packages/paw.git
http://git.debian.org/?p=debian-science/packages/geant321.git
http://git.debian.org/?p=debian-science/packages/mclibs.git
http://git.debian.org/?p=debian-science/packages/cfortran.git

If you prefer a monolithic SRPM package, you may try to have a look at older Fedora Project distributions ("equivalent" to Debian's "2006.dfsg.2-14" patchset, according to the included "CHANGELOG" file). Note that they also provide a separate "cernlib-g77" package ("equivalent" to Debian's "2006.dfsg.2-13" patchset, according to the included "CHANGELOG" file).
See, for example:
http://rpms.lip.pt/pub/f18/source/cernlib-2006-35.fc18.ndias.src.rpm
http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/16/Everything/source/SRPMS/cernlib-2006-35.fc14.src.rpm
http://pkgs.fedoraproject.org/cgit/cernlib.git/
http://rpms.lip.pt/pub/f18/source/cernlib-g77-2006-33.fc18.ndias.src.rpm
http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/16/Everything/source/SRPMS/cernlib-g77-2006-33.fc12.src.rpm
http://pkgs.fedoraproject.org/cgit/cernlib-g77.git/

A small additional note concerning Ubuntu ... it seems that in Ubuntu releases 11.10, 12.04 (LTS), 12.10 and 13.04 some of their CERNLIB 2006 related binary and development packages are "broken" (they are actually "empty" inside). For example, one of these "broken" packages is the "llibpdflib804-2-dev" in the version "20061220+dfsg3-1build1":

https://bugs.launchpad.net/ubuntu/+source/mclibs/+bug/1089411

Looking at all available Ubuntu "libpdflib804-2-dev" versions it can be seen that the old Ubuntu 10.04 (LTS) uses "2006.dfsg.2-5ubuntu3" and then the newest Ubuntu 13.10 uses "20061220+dfsg3-3". In both these cases, when one clicks the "List of files in package", one can see all required libraries and include files inside (so these packages are not "empty").

See also the site that announces
CERNLIB builds for the Large Hadron Collider

Jun 26, 2013:   CERNLIB 2005 for gfortran on newer Linux systems

Jacek M. Holeczek gave additional hints to let the CERNLIB build succeed:
On some newer systems (e.g. SL 6.X / SLC 6.X / CentOS 6.X / RHEL 6.X) the compilation of the "2005/src/pawlib/paw/xbae/cell.c" file may die with an error "freetype/config/ftheader.h: No such file or directory" (inspect the "2005/build/log/make.MMDD" file and search for the string "Error").

The problem is that, on these systems, "Xm" coming from OpenMotif will try to use "Xft" which in turn will try to use "freetype", which is actually the "freetype2" there (this problem does not appear when "Xm" comes from LessTif).

The CERNLIB "builder" is not prepared for it. The simplest brutal fix is to create an appropriate "backwards compatibility" symbolic link, either in the CERNLIB source tree:

    mkdir -p 2005/src/include
    ln -s /usr/include/freetype2/freetype 2005/src/include/
or in the standard system location:
    cd /usr/include
    sudo ln -s freetype2/freetype ./
and then rebuild CERNLIB from scratch.

Aug 04, 2010:   New version of CERNLIB for gcc-4.4 and gfortran

Jacek M. Holeczek was notified that gcc 4.4 introduces new problems. A new cernlib.2005.corr.2010.08.01.tgz has therefore be provided by him.

Then, in order to make the patched CERNLIB 2005 installation as "smooth" as possible on many new systems, he created a set of "patched" installation scripts cernlib.2005.install.2010.08.01.tgz (see also the "README_cernlib" file included in that tarball.

Both these tarballs have been tested with several gcc versions (and gfortran):
gcc 4.2.1 on openSUSE 10.3/i586
gcc 4.3.2 on openSUSE 11.1/x86_64
gcc 4.4.1 on openSUSE 11.2/x86_64
gcc 4.4.3 on Ubuntu 10.04/i686

Aug 05, 2009:   New version of CERNLIB for gcc-4.3.2 and gfortran

The latest cernlib.2005.corr.2009.06.13.tgz tarball has been provided by Jacek M. Holeczek. Some additional debian patches were applied in order to get cernlib working on systems with newer compilers (openSUSE 11.1/i586).

Feb 23, 2007:   Examples of the C / Fortran interface updated

An updated cernlib.2005.corr.tgz is provided which includes now also the modified code for cernlib's C / Fortran interface located in ./2005/src/cfortran/Examples .
 
Remark: In this directory I have added a script run_example which can be used to compile, link and run the examples. This requires that you have installed the ./2005/include directory after downloading the new cernlib.2005.corr.tgz and copying it into your installation.
Using your installation environment you should run:
    cd $CERN
    gtar -zxvf cernlib.2005.corr.tgz
    cd $CERN_ROOT
    mkdir include
    export CERN_INCLUDEDIR=$CERN_ROOT/include
    cd $CERN_ROOT/build
    gmake install.include
The compiled cernlib versions for SL4 and SL5 provided for download are updated already to include the modifications for ./2005/src/cfortran/Examples .
 

Feb 9, 2007:   LAPACK installation script modified

The script Install_lapack was modified to include the -fPIC compile option.
 
I assume that this is required for GENSER (Generator Services Subproject) and for the ATLAS offline/external generator code used in the ATHENA framework of ATLAS. The cernlib code itself (except the patchy stuff) has been compiled using this compile option.
Provided for download:  a compiled version for SL4 on x86_64   containing the lib, bin, and include subdirs (remark: libpacklib/libkernlib does not contain shift).
 
Remark: The cernlib distribution is runnning and has beeen tested now also on RHEL5 beta2 -> SL5   (which uses the gcc4 compiler suite including gfortran as default).
Provided for download:  a compiled version for SL5 on x86_64   containing the lib, bin, and include subdirs (remark: libpacklib/libkernlib does not contain shift).
 

Dec 12, 2006:   Reorganization of the CERNLIB distribution

Here is now the cernlib-2005-all-new.tgz and the info have been updated.
A patch which may be applied to the CERNLIB 2005 original distribution can be found here.
The installation scripts coming with cernlib-2005-all.tgz are now more structured and a script cernlib_env was added. This may be used in the directory which contains cernlibs "tar.gz" files if one has to reinstall some parts of cernlib, see cernlib install: "Installing Individual packages".
Again follow this procedure:
    download cernlib-2005-all.tgz to your installation directory
    run "gtar -zxf cernlib-2005-all-new.tgz"
    run "./Install_cernlib"
One can see all the cernlib code modified following this link.
 
For 64 bit architectures the following paw example (running in the pawdemo subdirectory) .
is now also executed correctly. Futhermore the example given in the HBOOK Reference Manual (section 9.3.1 - Using PAW and Unix shared memory) is working as expected.
Back to note from
For older notes on CERNLIB 2005 please see the historical entries  
 created:         Thu Jul 20, 2006 by Harald Vogt
 last updated:  Sun Feb  3, 2019 by