cling goes public!
Hi,
We, the cling team, have announced cling, our C++ interpreter prototype! (note: its SVN repository has changed compared with the announcement email; see the build instructions)
To a large extend thanks to Vassil's impressive commitment, cling now behaves like a good C++ interpreter: it runs C++ code that's entered, and prints the results.
[cling]$ #include <cmath> [cling]$ double x = std::sin(3.1) (double) 4.158066e-02 [cling]$ .L libz [cling]$ #include "zlib.h" [cling]$ zlibVersion() (const char * const) "1.2.3.4"
$ echo 'extern "C" const char* zlibVersion(); zlibVersion()' | cling -lz (const char * const) "1.2.3.4"
We have of course already added a few features that we liked from CINT - but cling is a completely new development, based on clang and llvm, a set of compiler libraries (to simplify the matter a bit :-) Vassil will present the innards of cling probably in October; I will post the slides here.
So what's special about cling? It's based on a production-grade compiler and it's designed taking decades of experience with CINT into account. And it doesn't need dictionaries! (Disclaimer: that does not mean that ROOT can do without, automatically. But that's our goal, of course.)
The next steps will be the ones most relevant for High Energy Physics: integration into ROOT (Paul is already working on that) and reloading of changed code (.x myCode.C, edit, .x myCode.C). That latter part is horrible for a compiler.
If you want to check cling out you can simply compile it yourself - it's really easy. I'd love to have an interactive, web-based interface once, but an online C++ interpreter is an invitation for script kiddies to hack the server :-( If you have an idea how to do it please let me know!
Cheers,

Re: multi-line mode
Hi Vladimir,
Thanks for your suggestion! Another option would be start editor-like behavior, where one moves up and down with the cursor keys, until one sends off the input using shift- or ctrl-enter. What do you think?
Note: this is just brainstorming - I'm not claiming that we have the time to implement it in 2012 :-) But if somebody is looking for something to contribute then this could be a nice extension!
Cheers, Axel
I think cling standalone is
re: cling binary
Hi Vladimir,
There are several possible modes of using the cling binary; for your context it's probably for evaluation. Yes, we need ".help". You do know that cling can run (.x) text files, too, right? For complex input that's usually what people do.
Just to remind you: we are building on almost two decades of experience with CINT, and it being used in production by tens of thousands of people. So when I say "people usually edit files" then that's the result of this experience :-) But that doesn't stop us from making fundamental changes, so who knows: if someone designs (with us) and contributed a nice multiline mode I wouldn't mind uploading it!
Cheers, Axel
how to handle a context which has multi lines
Re: multi-line input
cling compilation error
Cling Compilation
Keeping cling in sync with two repos is not an easy job :) I believe it is fixed now!
Cheers, Vassilcling compile 2 days later ;)
Re: targets=host!
Hi Matt,
You must configure with --enable-targets=host, else you will pull in all possible targets. As you are the second one reporting this we should probably work around that on the cling side...
Cheers, Axel.
Thank you !
Re: last good revsision
Hi Vladimir,
I prefer not to include llvm + clang in cling's repository. Instead cling now contains a file "LastKnownGoodLLVMSVNRevision.txt" which holds the highest revision number that is known to work. It gets updated by the Makefile, so there is a reasonable chance that this number stays relevant. Thanks for your suggestion!
Cheers, Axel
Is cling stable enough to be used in production application ?
Re: cling @ Windows, cling @ production
Hi Vladimir,
Thanks for your interest in cling! I would not recommend cling for running an airport. But if this is about e.g. a game - something where you control the consequences - then yes, I believe you can use cling as it is, in production. That's not so much because of cling but because of clang and llvm, which in turn are already used in production. Cling does not destroy them sufficiently to invalidate that :-)
There is one bug, though, that you would probably want to see fixed before you employ it: cling currently sometimes stumbles over the end of file token (or its incremental input) and crashes. I hope that this will get fixed in about four weeks.
I have never built cling on Windows 64bit, but it works nicely on Linux and MacOS 64bit. The biggest problem you might find is the Windows C++ ABI support that is to a large extent still missing in clang and thus in cling. If on Windows you restrain yourself to C you should be fine, though.
Cheers, Axel
Hi Axel, cling is really
Re: secret cling hacks!
Hi Vladimir,
Glad you like it! :-)
For out-of-class function definitions try the following:
Regarding the slow loading of windows.h: you can see whether it helps to turn some of the interpreter extensions off. You can e.g. use the same .rawInput as above.
Otherwise try a release build - the debug builds of llvm / clang are said to be much slower. And: windows.h is as evil a header as they can get :-) Any compiler chokes on it for a while. You can try to precompile it (e.g. into a module if that already works sufficiently on Windows), that should speed things up.
Cheers, Axel
Additional question
Re: cling-mt
Hi Vladimir,
You will be able to use cling in multi-threaded environments. I am not sure whether you can pull it off right now, but it's almost no work. Let me explain what's needed and what you will get.
The only global ("static storage") part in cling / clang / llvm is the setup: default target etc. Once that is done (and this should be done before spawning threads) everything else can be thread local. So once you are behind the setup phase cling is as thread safe as STL: don't access it across threads without locking, but you can have multiple instances, e.g. several per thread.
What still needs to be done is to move the initialization into a separate step, something that you could call before spawning threads. Right now this happens during construction of the Interpreter object and is thus not thread safe.
Contributions are always welcome - you have the source! ;-)
Cheers, Axel
The trunk did not worked as on 6Feb2012(not varified)
Re: Unresolved symbol in trunk
Hi James,
Thanks for your nice comment!
You were requesting all possible targets; just (also) pass --enable-targets=host to llvm's configure and it will work!
Cheers, Axel.
Build Issue
Undefined symbols for architecture x86_64: "llvm::sys::DynamicLibrary::LoadLibraryPermanently(char const*, std::string*)", referenced from: -exported_symbol[s_list] command line optionI'm on Mac OS X, using the latest (trunk) versions of the llvm, clang, and cling source. Trying to do a Release+Asserts build... Any idea what the issue is here? Thanks again!Re: Build Issue
Hi Dan,
Thanks for your positive feedback! You probably used the old SVN location instead of https://root.cern.ch/svn/root/trunk/cint/cling. I have updated the web pages, sorry about that.
WIth the current svn version of clang and LLVM, cling build for me just fine (also on Mac).
Cheers, Axel.
Hi Axel, Thanks for the
Optimized cling
Hi Dan,
Thanks for your comment! That makes perfect sense - we all build in debug mode all the time. These symbol exports are super fragile - platform specific, and as you show even influenced by the optimizer :-( Probably the only way to fix this is by creating a variable in libcling's dummy.cxx and assigning the address of llvm::sys::DynamicLibrary::LoadLibraryPermanently to it...
We do build in optimized mode once a while, to do performance measurements. I'll make sure we then fix this bug!
Cheers, Axel.
Just want to say thank you
Documentation
Thanks for trying it out.
You can find documentation in CLING_SRC_FOLDER/www/. It's work in progress but I think it's better than nothing.
VassilHow to use cling
Hi yoco!
Thanks for your comment! We, too, find cling amazing - also because we know from experience how difficult interpreting C++ is.
Regarding your question on how to use it: well, it's an interactive C++ interpreter. You type C++, it gets run, you see the trailing expression's value if you don't put the terminal ';'. There are a few shortcuts: .x MyCode.cxx(12) will load the file MyCode.cxx and call MyCode(12). .L mylib loads mylib.so. But that's basically it - it just understands all of C++.
We can definitely write something up within the cling pages. What exactly are you looking for? An extended version of the information I wrote here, basically a user manual?
Cheers, Axel
Does cling build on mac?
cling @ Mac
Hi Todd,
Thanks for your question! Yes, cling does build on the Mac. Usually! It's now fixed again, thanks for reporting!
Cheers, Axel
Hi, Thanks for the update
llvm[4]: Linking Debug+Asserts Shared Library libcling.dylib Undefined symbols: "clang::Diagnostic::~Diagnostic()", referenced from: -exported_symbol[s_list] command line option "clang::BuiltinType::getName(clang::LangOptions const&) const", referenced from: -exported_symbol[s_list] command line option "clang::CompilerInvocation::CreateFromArgs(clang::CompilerInvocation&, char const* const*, char const* const*, clang::Diagnostic&)", referenced from: -exported_symbol[s_list] command line option "clang::CreateLLVMCodeGen(clang::Diagnostic&, std::basic_string, std::allocator > const&, clang::CodeGenOptions const&, llvm::LLVMContext&)", referenced from:
-exported_symbol[s_list] command line option
"clang::ASTReader::getOriginalSourceFile(std::basic_string, std::allocator > const&, clang::FileManager&, clang::Diagnostic&)", referenced from:
-exported_symbol[s_list] command line option
ld: symbol(s) not found
collect2: ld returned 1 exit status
Any thoughts of what can be wrong? Cheers, KarolosMissing exports
Hi Karolos,
Thanks for reporting! This is now fixed. But cling has moved (we'll update the web page); it's now at svn co http://root.cern.ch/svn/root/trunk/cint/cling - you will find the update there.
Cheers, Axel.
Regarding on-line
Thanks!
Hi MD
Thanks a lot for your comment! I did not know that site. You are right, they must be doing exactly what we need.
Would you (or someone else) be interested in creating a PHP or whatever setup that can interface with cling?I will then take care of the protections - now that I know who to ask :-)
Cheers, Axel
Hi Alex! I'm not much into
IDEone
Hi MD,
Thanks for your suggestion! Will do; let's see what they say! Interpreters are stateful (and so the web server would need to keep the connection open etc) while compilers are not - but let's see, maybe we can come up with something.
Cheers, Axel
Hi Axel, thanks for so much
Excellent Questions!
Hi Marcelo,
Thanks a lot for the flowers! And you've asked some excellent questions. I think the answers actually warrant a separate blog entry: it's interesting and magic enough, and I know several people out there always wondered what these dictionaries are.
Sorry to make you wait, but not for long: I'll be on a workshop next week, a good moment for that new post :-)
Cheers, Axel.
hi, great! but perhaps one
-sclang trunk
Hi Sebastian,
Thanks for your comment! Yes, in good ROOT spirit, the trunk is the best. There are still constant changes in clang and llvm, so please use the trunk. I'll update the web page accordingly.
Thanks for trying it out!
Cheers, Axel.
Working revision combination
thanks for your blog.
I also tried to compile but figured out that some interfaces in clang changed between your post and my reading/trials.
I already wastedIt took me one day to find a (not properly) working combination of revisions in SVN and to hack into cling and clang ;-)Now I managed to build cling with clang/llvm and it (kind of) works standalone - but then I could not get it up and running with root (neither compiling with clang nor gcc) :-(
Could you please give your working combination of SVN revision numbers for LLVM, clang and cling to get me (and maybe others) started?
Thanks&bests,
Daniel
Trunk!
Hi Daniel,
You just did one of the first few bug reports on cling! ;-) Apologies, with Vassil having been on vacation and me being at a workshop, cling wasn't updated to clang's changes for a while. It now is, i.e. the trunk works again.
If the trunk ever doesn't work then it's a bug. Please complain and we'll fix it. Thanks for test driving it!
Cheers, Axel