Cling 1.1 for Ubuntu 22.04 and 24.04

For my fellow Ubuntu users out there, I’ve created native (.deb) Ubuntu packages for cling 1.1.

:tada: :drum: :tada: :drum:

They are located here: ppa:ppa-verse/cling

Installation is as easy as:

sudo add-apt-repository ppa:ppa-verse/cling
sudo apt install cling

(You may need to install software-properties-common, if your system can’t find the add-apt-repository command.)

The difference between these packages and the official way of building cling is that:

  1. These packages are linked dynamically against patched versions of LLVM-16 (which is also provided by the PPA). This means the size of the cling binary is several times smaller than the official statically linked one.

  2. Additionally, these packages provide a small wrapper script called cliche, which makes it very easy to pass arguments into your C++ scripts. Here is an example:

    runme.cpp:

    #!/usr/bin/cliche
    
    #include <array>
    #include <iostream>
    
    auto args = getargs();
    for(auto n = 0; n < args.size(); ++n) {
        std::cout << "args[" << n << "] = " << args[n] << std::endl;
    }
    

    Now, you can call runme.cpp as follows:

    user@linux:~$ ./runme.cpp foo bar baz
    args[0] = ./runme.cpp
    args[1] = foo
    args[2] = bar
    args[3] = baz
    
  3. And… you can also run cling on your beloved Raspberry Pi. Installation instructions are slightly different:

    sudo add-apt-repository -S deb https://ppa.launchpadcontent.net/ppa-verse/cling/ubuntu jammy main
    sudo apt install cling
    

    You may need to install software-properties-common and/or python3-launchpadlib if you get an error above.

  4. Share and enjoy.

D-mo

1 Like

Thank you for sharing. I was wondering how the wrapper is different from cling "arg1" "arg2"?

Very cool that things work now on Raspberry pi. If you are interested in sharing more information about your work please feel free to reach out via email to me and we can organize a talk.

Hi @dimitry_ishenko ,
My Ubuntu version: 24.04

I followed the above steps as you have mentioned and installed CLING in my ubuntu machine.
I get seg fault when upon launching CLING as below:
test@test-Z790-Taichi-Lite:~/Prabhu/CLING$ which cling
/usr/bin/cling
test@test-Z790-Taichi-Lite:~/Prabhu/CLING$ cling
Segmentation fault (core dumped)

test@test-Z790-Taichi-Lite:~/Prabhu/CLING$ ldd /usr/bin/cling
linux-vdso.so.1 (0x00007ffcac7fe000)
libLLVM-16.so.1 => /lib/x86_64-linux-gnu/libLLVM-16.so.1 (0x00007bb4c4000000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007bb4c3c00000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007bb4ced61000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007bb4ced34000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007bb4c3800000)
/lib64/ld-linux-x86-64.so.2 (0x00007bb4cee61000)
libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007bb4ced26000)
libedit.so.2 => /lib/x86_64-linux-gnu/libedit.so.2 (0x00007bb4cecec000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007bb4cecd0000)
libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007bb4c3f46000)
libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007bb4cec9c000)
libxml2.so.2 => /lib/x86_64-linux-gnu/libxml2.so.2 (0x00007bb4c3a1e000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007bb4cec84000)
libicuuc.so.74 => /lib/x86_64-linux-gnu/libicuuc.so.74 (0x00007bb4c3400000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007bb4c3f14000)
libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x00007bb4cb5f1000)
libicudata.so.74 => /lib/x86_64-linux-gnu/libicudata.so.74 (0x00007bb4c1600000)

Am I missing something here?

@vvassilev let’s say you have a C++ script that you want to run with cling:

script.cpp

#!/usr/bin/cling

#include <iostream>
auto name = "Vassil";
std::cout << "Hello " << name << std::endl;

Make it executable and now you can run it like so:

user@linux:~$ ./script.cpp 
Hello Vassil

What if you want to pass in the name as an argument to the script?

Problem #1: if you do this…

user@linux:~$ ./script.cpp Vassil
Hello Vassil
input_line_6:2:2: error: use of undeclared identifier 'Vassil'
 Vassil
 ^

… you get an error.

Problem #2: even if that worked, how do you access the args here?

#!/usr/bin/cling

#include <iostream>
auto name = ???; // HOW DO I ACCESS THE ARGS?
std::cout << "Hello " << name << std::endl;

That’s where cliche comes in handy. It simply wraps the args into the getargs() macro and passes it to cling using the -D option. In other words, we change the script to this:

script.cpp

#!/usr/bin/cliche

#include <array>
#include <iostream>
auto args = getargs();
std::cout << "Hello " << args[1] << std::endl;

And, now you can do this:

user@linux:~$ ./script.cpp Vassil
Hello Vassil

To be honest, I didn’t do much other than merging your patched version of LLVM-16 with Ubuntu’s version, plus adding Debian packaging on top of cling, and sending it all to the Launchpad to be compiled on all platforms. :speak_no_evil: :speak_no_evil: :speak_no_evil:

You can find my forks here:

The cliche wrapper is in the debian folder. I will drop you an email in case you still want to discuss anything.

D-mo

Try running from a different directory.

Ubuntu 20.04 is now also supported.