# Building custom interpreter in ROOT

**URL:** <https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988>\
**Category:** Newbie\
**Created:** [January 4, 2023, 9:52pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988 "2023-01-04T21:52:55Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![salz-root](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@salz-root](https://root-forum.cern.ch/u/salz-root)\
**Post date:** [January 4, 2023, 9:52pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/1 "2023-01-04T21:52:56Z")

</div>

Hi,

We used ‘custom CINT’ (CINT built with our proprietary compiled functions) many years ago with older versions of linux (Ubuntu 12.x and earlier). We are now moving to Ubuntu 22.x and would like to similarly build a custom interpreter like we had with CINT.

I was able to download the ROOT source and build it on our platform for simple command line usage to test it out. But I am not finding any similarities in terms of easily building ROOT with our compiled code like I did with ‘makecint’.

We don’t need all the power of ROOT. I think the best way is to use Cling but I am not sure if I am on the right track as I have not found anything that would integrate several source files into the interpreter. Perhaps I am not looking in the right place.

([Chapter: Cling](https://root.cern.ch/root/htmldoc/guides/users-guide/Cling.html#aclic-compiling-scripts-into-libraries))

Our code is quite extensive with its directory structure and makefiles that will build the dozens of .o files properly. The aim is to integrate the API into the interpreter so that users can write their own scripts with the functions defined in the API.

Where can I find examples/of building Cling with our code? Or is there another solution?

Thank you.

* * *

\_ROOT Version: v6.26.10  
\_Platform: Ubuntu 22.04  
\_Compiler: g++ 11.3.0

* * *

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 5, 2023, 8:57am UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/2 "2023-01-05T08:57:47Z")

</div>

Welcome to the ROOT forum.

As you noticed CINT has been replaced by CLING.  
You ar on the right track.  
You can follow the instructions given here:

> **[The C++ interpreter Cling](https://root.cern/manual/cling/#aclic-compiling-scripts-into-libraries)**
>
> Data Analysis Framework

---

<div class="post-metadata">

**Author:** ![salz-root](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@salz-root](https://root-forum.cern.ch/u/salz-root)\
**Post date:** [January 17, 2023, 9:47pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/3 "2023-01-17T21:47:11Z")

</div>

I have not made much headway. I was wondering if there is something wrong with my environment (build/installation) or just with my understanding. I am able to do a few things but nothing close to being able to get a single custom interpreter tool (say, ‘myroot’) that would have the ability to run a script that invokes functions that are built into ‘myroot’.

But before I go there, I’d like to know why I get 2 different outputs with the same script/source file if I execute it differently.

[mytest.c](https://root-forum.cern.ch/uploads/short-url/oYRKLREEAa7L1rKrveS6SLev82G.c) (737 Bytes)

From the linux command line, when I type

> root -l mytest.c -q

## my output is :

Processing mytest.c…

Is CINT Defined? - NO  
Is CLING Defined? - YES  
Is MAKECINT Defined? - NO  
Is ROOTCLING Defined? - NO

* * *

But when I type

> root -l mytest.c++ -q

## my output is :

Processing mytest.c…  
\<msg about creating shared library (no error)\>

Is CINT Defined? - NO  
Is CLING Defined? - NO  
Is MAKECINT Defined? - NO  
Is ROOTCLING Defined? - NO

* * *

Why the difference in CLING define status?

Thanks.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 18, 2023, 8:25am UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/4 "2023-01-18T08:25:44Z")

</div>

I get the same on Mac.  
@vvassilev should know why the outputs are different.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 18, 2023, 8:55am UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/5 "2023-01-18T08:55:38Z")

</div>

For me it’s obvious: “` __CLING__ `” is defined in “interpreted code” and not in “(pre)compiled code”.

> [@ROOT 6 / CLING / rootcling replacements for (\_\_CINT\_\_), (\_\_MAKECINT\_\_) and (\_\_ACLIC\_\_) macros](https://root-forum.cern.ch/t/root-6-cling-rootcling-replacements-for-cint-makecint-and-aclic-macros/27698):
>
> I am looking for ROOT 6 / CLING / rootcling replacements for ROOT 5 / CINT / rootcint macros \_\_CINT\_\_, \_\_MAKECINT\_\_ and \_\_ACLIC\_\_ (I would like to get rid of any ROOT 5 / CINT / rootcint dependencies in new ROOT 6 / CLING / rootcling source code): #if defined(\_\_CINT\_\_) && !defined(\_\_MAKECINT\_\_) // source code being actually interpreted by cint #elif defined(\_\_MAKECINT\_\_) // source code seen by rootcint only #elif defined(\_\_ACLIC\_\_) // source code being actually compiled by ACLiC #else // source…

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [January 18, 2023, 1:18pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/6 "2023-01-18T13:18:06Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> For me it’s obvious: “` __CLING__ `” is defined in “interpreted code” and not in “(pre)compiled code”.

Yes, that is absolutely right. Additionally, the ` __CINT__ ` and ` __ROOTCLING__ ` preprocessor macros are defined by `rootcling` during dictionary generation.

> [@salz-root](#):
>
> We don’t need all the power of ROOT. I think the best way is to use Cling but I am not sure if I am on the right track as I have not found anything that would integrate several source files into the interpreter. Perhaps I am not looking in the right place.

Did you progress with that? If you don’t need any features from ROOT, but just the C++ interpreter services, then you should probably take cling as a (leaner) base.  
If you want to use cling as a library from your program, here is an example that can be used as a starting point: [cling/tools/demo at master · root-project/cling · GitHub](https://github.com/root-project/cling/tree/master/tools/demo).

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![salz-root](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@salz-root](https://root-forum.cern.ch/u/salz-root)\
**Post date:** [January 19, 2023, 2:56pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/7 "2023-01-19T14:56:13Z")

</div>

OK. I thought both my invocations execute “mytest.c” in the interpreter mode though the one with ++ first creates a library of the source. Without the -q, I’d stay in the interpreter (root prompt).

---

<div class="post-metadata">

**Author:** ![salz-root](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@salz-root](https://root-forum.cern.ch/u/salz-root)\
**Post date:** [January 19, 2023, 3:23pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/8 "2023-01-19T15:23:35Z")

</div>

Thank you.

When I tried doing some things on the lines of the demo, I got several errors of the “not found”, “not defined” nature. For ex., make could not resolve

#include \<cling/Interpreter/Interpreter.h\>

I can see the above header file in several subdirectories but don’t understand why the path for the right one is not set. On another error, I specified the path (to cmake) with -D and got a warning that “manually specified variables were not used”.

I decided to rebuild cling in case I had missed something the first time. Using this -

> **[Cling Build Instructions](https://root.cern/cling/cling_build_instructions/)**
>
> Data Analysis Framework

I noticed an error on the build instructions. The following line in the second block of commands to confiigure and build cling -

cmake -DCMAKE\_INSTALL\_PREFIX=[Install Path] -DCMAKE\_BUILD\_TYPE=[Build configuration, e.g. Release or Debug] …\src

It should be -

cmake -DCMAKE\_INSTALL\_PREFIX=[Install Path] -DCMAKE\_BUILD\_TYPE=[Build configuration, e.g. Release or Debug] …/…/src

In the first block of instructions to check out from Git, we _cd_ down 3 levels from top, then _cd_ up 2 levels. We are in “src” where we do _mkdir build_ and then _cd build_. Now “src” is two levels up.

(Minor bug - there is a mix of forward and back (Windows?) slashes for paths)

I saw something similar while building root.

After my build of cling completes, I will see what I can do and report back. Thank you.

---

<div class="post-metadata">

**Author:** ![salz-root](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@salz-root](https://root-forum.cern.ch/u/salz-root)\
**Post date:** [January 19, 2023, 3:32pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/9 "2023-01-19T15:32:11Z")

</div>

I don’t know why my msg above puts 3 dots in the paths instead of 2. Editing only shows 2 dots.

Could someone point me to the tools for posting on this forum? It does not have some std features I am used to (I am not seeing/finding them). For example, how to quote a post selectively before replying, how to mark something as a code block etc. Is there a way to preview how the post is going to look before I press “Reply”?

When I clicked on the " on the toolbar, it printed “\> Blockquote”. No idea what that would do and didn’t want to quote an entire post.

Thanks…

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 19, 2023, 6:14pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/10 "2023-01-19T18:14:52Z")

</div>

@salz-root In principle, most of the [Markdown](https://en.wikipedia.org/wiki/Markdown), [BBCode](https://en.wikipedia.org/wiki/BBCode) and [HTML](https://www.w3schools.com/html/html_formatting.asp) text formatting should work.

See also: [Uncle Google → Discourse code formatting](https://www.google.com/search?q=Discourse+code+formatting)

---

<div class="post-metadata">

**Author:** ![salz-root](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@salz-root](https://root-forum.cern.ch/u/salz-root)\
**Post date:** [January 20, 2023, 9:24pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/11 "2023-01-20T21:24:44Z")

</div>

@jalopezg ,

I downloaded and rebuilt cling.

When I try to build the example project that you pointed me to, I get the same errors that I was getting with my own experiments. I am using the _cmake_ command specified on this page :

> <https://github.com/root-project/cling/tree/master/tools/demo>
>
> //github.com/root-project/cling/tree/master/tools/demo

> cmake -Dcling\_DIR=/cling-install-dir/lib/cmake/cling /cling-source-dir/tools/cling/tools/demo

I get error for the CMakeLists.txt file : line 25 (find package)  
It says it can’t find a package config file provided by cling with either of these names:  
clingConfig.cmake  
cling-config.cmake

When I searched, I found:

/cling-install-dir/lib/cmake/cling/ **C** lingConfig.cmake  
/cling-build-dir/lib/cmake/cling/ **C** lingConfig.cmake

So, I copied **C** lingConfig.cmake to **c** lingConfig.cmake in the install-dir and the error went away.

Since the cling config files I found have an uppercase C in the name, I tried -DCling\_DIR in the cmake command and got this warning for Cling\_DIR -  
“manually specified variables were not used by the project”

Is copying the “ClingConfig.cmake” to “clingConfig.cmake” the right way forward?

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [January 26, 2023, 12:39pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/12 "2023-01-26T12:39:30Z")

</div>

> [@salz-root](#):
>
> clingConfig.cmake  
> cling-config.cmake

I cannot see any mention to these files (only to `ClingConfig.cmake`) neither on `master` or the `v0.9` tag. Which revision have you checked out of the cling repository?

> [@salz-root](#):
>
> So, I copied **C** lingConfig.cmake to **c** lingConfig.cmake in the install-dir and the error went away.

Makes sense; maybe some renaming that happened in the past and that I am not aware of.

> [@salz-root](#):
>
> Is copying the “ClingConfig.cmake” to “clingConfig.cmake” the right way forward?

So it seems.

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![salz-root](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@salz-root](https://root-forum.cern.ch/u/salz-root)\
**Post date:** [January 26, 2023, 2:58pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/13 "2023-01-26T14:58:58Z")

</div>

My _cling_ version is 1.0-dev

I checked it out and built it using [these instructions](https://root.cern/cling/cling_build_instructions/) on Jan 20, 2023.

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [February 28, 2023, 11:20am UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/14 "2023-02-28T11:20:32Z")

</div>

Hi @salz-root; let me know how this is progressing; any issues so far?

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![salz-root](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ccd318/32.png) [@salz-root](https://root-forum.cern.ch/u/salz-root)\
**Post date:** [February 28, 2023, 3:10pm UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/15 "2023-02-28T15:10:14Z")

</div>

Hi @jalopezg

I am at a dead end. I started [another thread](https://root-forum.cern.ch/t/augmenting-cling-with-custom-functions/53250) to find a solution via _Cling_ because we mostly need an interpreter and not the other features of ROOT. My requirements and limitations are described in that thread.

I am able to build (a kind of) custom _Cling_ with a shared library that has our proprietary functions but don’t have many answers that would enable us to use _Cling_ instead of _Cint_ for our existing tool set of test scripts.

With _Cint_, it was possible to automate some functionality and do things “behind the scenes” without requiring the user to type anything. I have been unable to find similar features in _Cling_ so far.

Thank you for asking.

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [March 1, 2023, 7:00am UTC](https://root-forum.cern.ch/t/building-custom-interpreter-in-root/52988/16 "2023-03-01T07:00:20Z")

</div>

Closed on March 1, 2023, 7:00am UTC

This topic was automatically closed after 10 hours. New replies are no longer allowed.
