# Weird error output from Cling

**URL:** <https://root-forum.cern.ch/t/weird-error-output-from-cling/19410>\
**Category:** Cling\
**Created:** [June 22, 2015, 4:24pm UTC](https://root-forum.cern.ch/t/weird-error-output-from-cling/19410 "2015-06-22T16:24:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![KD0BPV](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/c68b51/32.png) [@KD0BPV](https://root-forum.cern.ch/u/KD0BPV)\
**Post date:** [June 22, 2015, 4:24pm UTC](https://root-forum.cern.ch/t/weird-error-output-from-cling/19410/1 "2015-06-22T16:24:35Z")

</div>

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:

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

What did I break, or is this a bug?

test.cpp:

```auto
//#! /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;
}
```

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [June 25, 2015, 6:47pm UTC](https://root-forum.cern.ch/t/weird-error-output-from-cling/19410/2 "2015-06-25T18:47:00Z")

</div>

Hi,

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

```auto
#! ../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:

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

Cheers, Axel.

---

<div class="post-metadata">

**Author:** ![KD0BPV](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/c68b51/32.png) [@KD0BPV](https://root-forum.cern.ch/u/KD0BPV)\
**Post date:** [June 26, 2015, 3:14am UTC](https://root-forum.cern.ch/t/weird-error-output-from-cling/19410/3 "2015-06-26T03:14:38Z")

</div>

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](https://root-forum.cern.ch/uploads/default/original/2X/3/392654bcd5a9eb3af3841f04e3d82fa65d648eb6.txt) (77.5 KB)

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [June 26, 2015, 5:16am UTC](https://root-forum.cern.ch/t/weird-error-output-from-cling/19410/4 "2015-06-26T05:16:26Z")

</div>

Hi,

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

Cheers, Axel.

---

<div class="post-metadata">

**Author:** ![cw2636](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/a9adbd/32.png) [@cw2636](https://root-forum.cern.ch/u/cw2636)\
**Post date:** [December 12, 2023, 11:12pm UTC](https://root-forum.cern.ch/t/weird-error-output-from-cling/19410/5 "2023-12-12T23:12:19Z")

</div>

@Axel How can we incorporate this with int main (int argc, char \*\* argv). How do we call it at the end. For any functions with arguments how do we call it at the end.
