Struggling with cling in Jupyter

Hi, new to cling and trying to get it working with Jupyter in hopes of deploying for educational purposes.

versions:
latest cling/clang/LLVM built yesterday
g++ 4.9.3
Jupyter 4.1.0
Python 3.4.3

In brief, I’ve built cling several times using several different methods (clone.sh, manually, etc.) The cling executable seems to work perfectly. However, when I try code in Jupyter using the cling kernel, I get lots of error messages, and often, the kernel dies. (This is testing with code that works fine in cling.)

For example:

#include <iostream> std::cout << "Hello, world!" << std::endl;
Gives the following error message:

[code]input_line_3:3:6: error: no type named ‘cout’ in namespace 'std’
std::cout << “Hello, world!” << std::endl;

input_line_3:3:11: error: expected unqualified-id
std::cout << "Hello, world!" << std::endl;
          ^[/code]
and the kernel dies.

This code:
[code]int x = 0;
x++;
x[/code]
gives correct output, but also an error message:
[code]Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/cling-kernel/clingkernel.py", line 143, in publish_pipe_output
    data = self._recv_dict(self.output_pipe)
  File "/usr/local/lib/cling-kernel/clingkernel.py", line 131, in _recv_dict
    value = os.read(pipe, len_value).decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 9-10: invalid continuation byte[/code]

Any help would be appreciated!

-Christopher

Hi Christopher,

The first issue is that cling currently doesn’t separate declarations and expressions itself. It will work with two cells, one with the #include, another with piping to cout. That’s on our list.

The second one is weird. Looks like a sync issue in the Jupyter communication. I’m checking…

Cheers, Axel.

Hi,

I cannot reproduce the second issue with the current master. I have been trying this on MacOS X 10.10.4, XCode 7.3 - which platform are you on? Which Linux distro?

Cheers, Axel.

Hi Axel, thanks for your response! Separating the #include into a separate cell fixed the problem. The other issue was not happening in isolation, but when I already had a cell containing the problematic code; with that problem solved, the other problem also went away. (If you still want to know, I’m on linux Mint 17 - essentially Ubuntu 14.04)