(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:
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.
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
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.
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.
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)
@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:
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.
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.