How to install Cling on Linux or WSL
In the previous post, I briefly mentioned an overview of how the cling interpreter works, so if you haven’t checked that post out, I encourage you to go and have a look at it.
Setting Cling Up:
Requirements:
Cling is built on top of Clang, hence it, unfortunately, works only on the platforms where clang feels at home, which is not windows.
You need a Unix-like operating system.
you can however still use Cling on WSL (Windows Subsystem for Linux), which is available with Window 10 64 bit.
How to install Windows Subsystem for Linux (WSL) — Windows 10
Installing Cling:
Manual Install:
Method 1:
Open up the bash terminal and enter the following commands (in order):
git clone http://root.cern/git/llvm.git cling_srccd cling_srcgit checkout cling-patchescd toolsgit clone http://root.cern/git/cling.gitgit clone http://root.cern/git/clang.gitcd clanggit checkout cling-patchescd ../..mkdir buildcd buildcmake -DCMAKE_INSTALL_PREFIX=[Install Path] -DCMAKE_BUILD_TYPE=[Build configuration]..\srccmake --build .cmake --build . --target install
Replace [Install Path] with the folder you want to install in.
For example, “/home/ubuntu/” in my case.
And [Build configuration] with “RELEASE”.
Method 2:
Cling also provides binary snapshots for Ubuntu (as well as Fedora and OSX) which you can find here https://root.cern.ch/download/cling
For example, if you are on ubuntu 18:
1. sudo apt install -y wget unar2. wget https://root.cern/download/cling/cling_2020-11-05_ROOT-ubuntu18.04.tar.bz23. unar cling_2020-11-05_ubuntu18.04.tar.bz24. ./cling_2018-09-21_ubuntu16/bin/cling
Replace the URL in wget with the latest one or the one you want from the link.
Automated Install:
Copy and paste the bash script in the following link into a file.
https://raw.githubusercontent.com/Axel-Naumann/cling-all-in-one/master/clone.sh
1. touch cling_install.sh2. nano cling_install.sh (or open in any text editor)3. Paste the bash script, save and exit. ctrl+s and ctrl+x for nano.4. bash cling_install.sh5. This may take a while. so, sit back and relax
Running Cling:
To run, cling:
cd into the [INSTALL_FOLDER]/bin and then do ./cling
cd [install_path]cd bin./cling
Wheww… Lots of work to do right?
You may want to simplify it.
From anywhere in the system just entering
$ cling
should open up the interpreter.
Adding and Alias:
This can be done in the following way:
nano ~/.bashrc
2. Scroll down until you see
3. Add a new alias here:’
Enter cling from anywhere and voila, there you have it, C++ interpreter ready to test your code on the fly.