You are here

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,
 

Comments

I use the cross build toolchian built a cling for windows 32 bits, and modify some source code in CIFactory.cpp (find the include path). the cling.exe can do "printf("test!\n");", but it cannot load the dll file, dose it have any plan to support in windows system?? Thanks, ChuYuan Chiang

Hi ChuYuan Chiang,

Thanks for your question! There are two parts. For not being able to load a DLL, that's a bug that you can now follow up in our bug tracker. We might not be able to reproduce the issue; it would be good if you could provide us with more information of how exactly it fails, e.g. by sending the error message to cling-dev@cern.ch

Windows support is still severely limited: we currently cannot use the newest clang which has much improved "native" Windows C++ ABI support. OTOH, C on Windows should just work. We are planning on getting cling to work with the head of clang's trunk again during the first half of this year.

Cheers, Axel

Hi Axel, Is planned cling to work with Visual Studio 2013 64 bit after the first half of this year ? As far as I understand the current cling version C language should work with Visual Studio 2013 ? Thanks, Vladimir

Hi Vladimir,

Good question! My colleague Bertrand is making lots of progress with Windows support: cling now works with the newest MSVC in C++ mode (with exceptions off)! We currently plan to get ROOT 6 to work with 32bit first and deal with 64bit later.

Cheers, Axel.

How does one build with MSVC ? Any chance you could tell us some of the steps you/Bertrand did to build the latest cling with MSVC?

Hi Vladimir,

2016 is the year for cling on MSVC! ;-) I am currently updating cling to work with the current master of llvm + clang. Once that's done we will revisit cling on MSVC. We know that clang's support has become much more complete.

Cheers, Axel.

Hi, How you would briefly compare cling with alternative projects: Ceemple, Julia, chaiscript ? Thanks, Vladimir

Hi Vladimir,

Well, cling for for C++, to begin with :-) You're welcome to do a proper comparison and post the link here!

Cheers, Axel

Is it possible to redefine (unload or clean) functions, variables and classes in cling interpretator?

Hi Andrey,

Thanks for your question! Yes, since recently you can undo declarations; ".undo 2" reverts the two previous declarations.

Cheers, Axel.

Is there any progress to support Windows ?

Hi Vladimir,

Some progress on the clang side, but fundamental things still didn't work last time we tried. I will definitely post once Windows support is there!

Cheers, Axel.

Hi Vladimir,

Brilliant idea! Like that it's not useful for ROOT and we cannot run the cling test suite - but at least we can build it! Watch the commit logs for updates - but I suspect that this will not arrive for another month... we are approaching an integration deadline for ROOT and a conference is coming up.

Thanks again for your suggestion!

Cheers, Axel.

There is a similar project called geordi-prime, it's a haskell-based c++ eval irc bot. The only difference is that it cannot keep state. Anyway, it's publicly available on freenode irc (and countless copies are available elsewhere) and it seems its safety measures are more than enough for irc wannabe hackers. The web-based cling could use the same idea to make sure its safe.

The webpage of geordi-prime: http://www.eelis.net/geordi/

Cling is really great !!!

I was able to integrate it in my System on Windows and not I can use C++11 interactively.


Unfortunately there are still some problems with it.
If I try to do following:

 

#include "my_header.h"


and header includes some other headers that Cling can not find then it will
CRASH in ASTNodeEraser.cpp .

 

Hi Devid,

Thanks for trying it out! As we said quite a few times already: cling is not supported on Windows yet. I'm surprised it even starts up. Sorry. This is only going to change next year. We do welcome patches even before, though!

Cheers, Axel

Hello, I've successfully compiled Cling on Mac OSX and seems to work for simple C++ expressions. However when I try to create a C++ function I have a strange error:

[cling]$ void ff() {
[cling]$ ?   int mm;
[cling]$ ?   mm = 5;
[cling]$ ?   }
input_line_4:2:11: error: expected ';' at end of declaration
 void ff() {
          ^
          ;
[cling]$

This is expected behaviour or am I doing something wrong ?

Hi,

The preparseing doesn't work yet and defining a function should happen with the meta command:

[cling]$.rawInput
[cling]! void ff() {
[cling]! ?   int mm;
[cling]! ?   mm = 5;
[cling]! ?   }
[cling]$.rawInput

 

Vassil

Hello, The statement "If you want to check cling out you can simply compile it yourself - it's really easy." sounds interesting ... but the time to build cling is extremely high. It takes round about 12h on dual core machine (2.2 Ghz) ! Is there a way to get a binary version for i386 LINUX ? --Armin

Hi Armin,

No way does it take 12h, something must be terribly wrong with your setup. It should take < 30 minutes even on a laptop. Nevertheless you can pick up a binary version of cling here: https://ecsft.cern.ch/dist/cling Don't be scared by the invalid SSL certificate: it's the best CERN can give to us...

Cheers, Axel

Hi Vladimir,

Not that I am aware of. We will only get to that next year - unless someone else contributes patches before.

Cheers, Axel.

is the export definition outdated? _ZN4llvm11raw_ostream5writeEPKc* -> _ZN4llvm11raw_ostream5writeEPKcj _ZN4llvm5APInt12initSlowCaseEj* -> _ZN4llvm5APInt12initSlowCaseEjyb _ZTVN4llvm16JITEventListenerE -> _ZN4llvm16JITEventListenerD2Ev _ZN4llvm15SmallVectorBase8grow_podE* -> _ZN4llvm15SmallVectorBase8grow_podEjj dunno about * but gcc refuse that and when build llvm as shared library, cling throw local_cxa_atexit symbol unresolved or something during startup. static library of llvm doesn't cause this

Hi,

Okay, so you are building with GCC on Windows - which one, MingW or cygwin? None of that has ever been tried to my knowledge, and it's unfortunate that the linker doesn't cope with the exports table.

The local_cxa_atexit symbol might not even be needed when building with GCC. Could you open a bug report at https://savannah.cern.ch/bugs/?func=additem&group=savroot? I cannot promise that this will get fixed soon, foryhour configuration, but I would nonetheless like to have a reminder that this issue exists.

For now you are much better off building cling on Linux or MacOS. Take a virtual machine and off you go!

Cheers, Axel

I'm sorry but i'm total noob at linux Axel :) I dunno why, everytime i try linux it took less than a day to make me revert to windoze XP :D I use gcc 4.6.3 mingw/msys. you mean that wildcard supposed to resolved by the gcc's linker?

Hi,

Sorry - if you cannot get it to work on Windows yourself you're out of luck for now... We will attack cling on Windows only next year.

Cheers, Axel.

Hi Axl, I build latest cling for windows, apparently load module .L doesn't work as expected (in the example) [cling]$ .L libz input_line_6:1:10: fatal error: 'libz' file not found #include "libz" Load file failed. I have put zlib.dll zlib.dll.a zlib.a in current folder. Even set LLVM_LIB_SEARCH_PATH doesn't help. More importantly why it treated as #include "libz"? Thank you Axl, cling is great for learning!

Hi,

"zlib" and "libz" are not the same words :-) Try to rename it to libz.dll, or try .L zlib. And please remember that Windows support is still limited for cling due to clang not fully supporting the Windows C++ API yet.

I'm happy to hear that you like cling, even though you take the rocky Windows road!

Cheers, Axel

This time I tried diagnose it with filemon (lowlevel filesystem API monitoring), cling first try exact keyword, then add prefix lib and suffix .a if not found if I use .L libz and cling found static/import library it will complain "Bad image" so I assume it's libz.dll that asked? tried .L zlib.dll and cling found it but throw

Hi,

Sorry, we'll be able to help with the Windows build only next year.

Cheers, Axel.

After I use the make command in the build directory I get this error. I am trying to compile cling. SyntaxError: invalid syntax make[2]: Entering directory /home/ryan/Documents/build/tools/cling' llvm[2]: Updating Makefile make[2]: Leaving directory/home/ryan/Documents/build/tools/cling' svn: '/home/ryan/Documents/llvm' is not a working copy File "", line 1 if >= : print "skip" ^ Any help would be appreciated. Thank You.

I have built clang/llvm but clang++ doesnt seem to work and i think it could potentially be due to the fact that clang++ only works with mac os as far as i know..could i still run cling if clang++ doesnt work...just to clarify clang works perfectly and it compiles my c code flawlessly just clang++ doesnt work. I am using ubuntu 10.04 Thanks!

Hi,

Please discuss clang issues at the clang mailing list cfe-dev@cs.uiuc.edu.

Cheers, Axel.

Hello, since i get some errors both during linking (of rootcling_tmp; gives undefined symbol _ZTVN5clang13PragmaHandlerE, though libCling.so is on the path) and compiling (no matching function for call to ‘cling::Interpreter::createUniqueName()’) of ROOT with cling enabled, is it possible to have smth similar to cling's LastKnownGoodLLVMSVNRevision.txt in ROOT? i.e. some way of telling which revision of Cling does the currently checked-out ROOT revision compile (and link) with?

cheers, Constantin

Hi Constantin!

Thanks for your question. cling is now distributed as part of ROOT, so there cannot be any revision mismatch.

I have updated the build instructions - maybe it's now clearer that one should not build cling next to clang if using ROOT. And I assume that's what's happening in your case, because you seem to have an old libCling used by a new rootcling.

Also, please submit bug reports like this to Savannah, that help's us triaging them properly. Thanks!

Cheers, Axel

Any help much appreciated: llvm[4]: Linking Debug+Asserts Shared Library libcling.dylib Undefined symbols: "llvm::APInt::initSlowCase(unsigned int, unsigned long, bool)", referenced from: -exported_symbol[s_list] command line option "cling::Interpreter::executeFile(std::basic_string, std::allocator > const&)", referenced from: -exported_symbol[s_list] command line option

Thanks for the fix. I'll use your bug tracker in the future. I wasn't certain that it was a bug and not just something missing on my end. I still get one undefined symbol with latest SVN: "cling::Interpreter::createUniqueName()", referenced from: -exported_symbol[s_list] command line option

Hi,

Thanks for your reports; these things just happen because we still haven't integrated cling into our continuous integration system. I assume it was you who submitted this as a bug on savannah, that's really helpful, thanks a lot!

Cheers, Axel

What would cause this after clang builds fine: llvm[4]: Linking Debug+Asserts Shared Library libcling.dylib Undefined symbols: "llvm::APInt::initSlowCase(unsigned int, unsigned long, bool)", referenced from: -exported_symbol[s_list] command line option "cling::Interpreter::executeFile(std::basic_string, std::allocator > const&)", referenced from: -exported_symbol[s_list] command line option "cling::Interpreter::loadFile(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const*, bool)", referenced from: -exported_symbol[s_list] command line option "cling::MetaProcessor::process(char const)", referenced from: -exported_symbol[s_list] command line option (maybe you meant: cling::MetaProcessor::process(char const, cling::Value*))

Hi,

Thanks for your report - should be fixed! But please future report bugs at our bug tracker.

Cheers, Axel.

I use win32 compiled cling.exe, it hangs up in the simplest cases: int i=1; - OK int i=1 - without ";" - hangs up ++i; - OK ++i - hangs up #include "stdio.h" - OK #include "math.h" - hangs up #include "math_not_exist.h" - OK, informs about error What going wrong in these cases ? Thanks, Vladimir

Hi Vladimir,

Thanks for your report! C++ on Windows is still only rudimentary supported by clang. And cling depends on clang. The available features have already much improved over the last few months - but e.g. the ValuePrinter template instantiation (needed to print the value of the expression when omitting the ';') still causes an infinite loop on Windows. That's Vassil's diagnosis.

As templates are pretty fundamental for C++, and as work on the Windows C++ ABI has been picked up recently, there is hope that this will get fixed in the near future. We at CERN also need cling to work on Windows...

On Windows, today, cling should work in C-mode (cling -x c).

Cheers, Axel

Hi Axel, I'm a bit confused. Please clarify what options I have now to use cling in production win application ? As far as I understood in both win32 and win64 cases I can use C language only (until clang will fully support C++ in win32 and win64). It means that I should write C wrappers for C++ DLLs and any C++ code that I want to embed ? Another critical issue, you wrote that there is a critical bug that will be fixed in the nearest 4 weeks - cling sometimes crashes in the end of parsing... Is it applicable for win32/win64 C too ? Thanks, Vladimir

Hi Vladimir,

As I said, I expect cling on Windows to only work in C mode for the time being. The other bug will affect cling on Windows, too, whether C mode or not - it's about input buffer handling which is the same everywhere. I hope that clarifies the situation. As it is right now I would not recommend cling for production use on Windows. But I cannot predict how long it will take clang to support (most of) Windows C++ ABI: could be months, could be days.

Cheers, Axel

Pages