Weird error output from Cling

I’m getting some weird errors from cling when I try to run a test script through it. The same code works just fine through cint. If I don’t uncomment any she-bangs, clang and gcc also compile it fine, and the binary works as expected.

Here’s the output from ./test.cpp and cling test.cpp when I uncomment the cling she-bang:

input_line_6:3:1: error: expected expression public: ^ input_line_7:2:10: warning: empty parentheses interpreted as a function declaration [-Wvexing-parse] int main() ^~ input_line_7:2:10: note: replace parentheses with an initializer to declare a variable int main() ^~ = 0 input_line_8:3:6: error: variable has incomplete type 'Foo' Foo f; ^ input_line_5:2:8: note: forward declaration of 'Foo' class Foo ^

Additionally, if I comment the she-bang back out and run cling test.cpp, all I get is:

warning: cannot find function 'test()'; falling back to .L

What did I break, or is this a bug?

test.cpp:

//#! /usr/bin/cling
//#! /usr/bin/cint

#include <cstdio>

class Foo
{
public:
	void bar()
	{
		printf("This is foobar'd\n");
	}
};

int main()
{
	Foo f;
	printf("Hello World\n");
	f.bar();
	return 0;
}

Hi,

Sorry for the late reply. For now you’ll need this:

#! ../obj/interpreter/llvm/obj/Debug+Asserts/bin/cling --metastr=//.

//.rawInput
#include <cstdio>

class Foo {
public:
  void bar() {
    printf("This is foobar'd\n");
  }
};

int test() {
  Foo f;
  printf("Hello World\n");
  f.bar();
  return 0;
}
//.rawInput

test();

Let me explain:

  • //. allows you to keep the C++ code valid, and still make it interpretable. Optional.
  • The curlies need to go onto the same line to trigger continuation. That’s something we might get fixed once we overhaul how the pre-parsing works for cling - at the moment we’ll just send line by line to clang, and “class Foo” is not really helpful for clang…
  • to declare functions (again because of the code detection / pre-parsing issue) you’ll have to switch to .rawInput
  • don’t use main() - cling already has one
  • At the end I explicitly call the function to be called; as I said, each line is passed to the interpreter.

Hope that helps! For me, that produces:

Using raw input
Not using raw input
Hello World
This is foobar'd

Cheers, Axel.

Thanks, Axel. I appreciate the information. Also, that was actually fairly quick from what I’m used to on other forums, so no worries about the “late reply”.

Regarding #! ../obj/interpreter/llvm/obj/Debug+Asserts/bin/cling --metastr=//., will it still work if I instead do #! /usr/bin/cling --metastr=//.? I ask because I have no idea where your path is at, since it starts with “…”, which resolves to the parent directory. As I’m running the script from my home directory (/home/mark), that would resolve to /home/obj/interpreter/llvm/obj/Debug+Asserts/bin/cling, which does not exist. lol

If it not, below is an attached list of the files owned by the cling package I generated. I hope that’ll be enough information to help get me pointed in the right direction. I already tried searching it with the following regex, with no success: .*Debug\+Asserts.*

Thanks again,
Mark

cling-git_files.txt (77.5 KB)

Hi,

Sorry - that path was a red herring that I wanted to eat before pushing submit… Your path is just fine.

Cheers, Axel.