Install Cling and It's Jupyter Kernel from Source Code

Install Cling and It's Jupyter Kernel from Source Code

Introduction

Cling is an interactive C++ interpreter like ipython for Python. It provides an REPL environment, so we can type and execute C++ code dynamically. Cling has a jupyter kernel which put everything on a web page.
The project is here

Cling Installation

Download binary package is the simplest way to use it. But sometimes there is no right package for our development environment. We need build it ourself. Cling has a tool named cpt.py to do that. It needs Python 2.7 or later.

wget https://raw.githubusercontent.com/root-project/cling/master/tools/packaging/cpt.py
chmod +x cpt.py
./cpt.py --check-requirements && ./cpt.py --create-dev-env Debug --with-workdir=./cling-build/

Go to the bin directory under the build dir, here is cling-build/builddir/bin. Try ./cling. If you're lucky enough, [cling] would be on the monitor, it works now. Use .help command to get more information.

CMake issues

the CPT.py tool needs CMake version > 3.4. But if you use CentOS 7.2 like me, the default CMake is 2.8. To install CMake3, type

yum install cmake3

Then there are two versions CMake 2 and 3 in the OS. But the cpt.py still uses the default one. You don't need change OS setting or the script. cpt.py uses
CMAKE = os.environ.get('CMAKE', None)
to get the path to CMake tool.

Just set a environment variable CMAKE to cmake3.
EXPORT CMAKE=/usr/bin/cmake3

Run the installation script again.
./cpt.py --check-requirements && ./cpt.py --create-dev-env Debug --with-workdir=./cling-build/

Jupyter Kernel Installation

Add cling's path to PATH.
export PATH="~/cling-build/builddir/bin:$PATH"

Go to the jupyter kernel folder to install them. Some
cd cling-build/builddir/share/cling/Jupyter/kernel
pip install -e .

We use our builddir to do that. There is another directory cling-build/cling/share/cling/Jupyter/kernel, we can install kernels from it also. But sometime it causes jupyter error. Because cling-build/cling/lib misses nessessary library files.

Finally register for the kernelspec
jupyter-kernelspec install cling-cpp11

If you don't have root permission, you need to turn on --user option
jupyter-kernelspec install cling-cpp11 --user

Comments