# Standalone ROOT Terminal / Cling Interpreter in C++ CMake project

**URL:** <https://root-forum.cern.ch/t/standalone-root-terminal-cling-interpreter-in-c-cmake-project/43464>\
**Category:** Evolution Proposals, Apps & Ideas\
**Tags:** cling\
**Created:** [February 9, 2021, 12:30pm UTC](https://root-forum.cern.ch/t/standalone-root-terminal-cling-interpreter-in-c-cmake-project/43464 "2021-02-09T12:30:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [February 9, 2021, 12:30pm UTC](https://root-forum.cern.ch/t/standalone-root-terminal-cling-interpreter-in-c-cmake-project/43464/1 "2021-02-09T12:30:10Z")

</div>

When integrating ROOT libraries in a standalone C++ CMake project, I sometimes miss the flexibility that the scripts and cling interpreter gives you.

I had the idea of porting the official ROOT GUI tutorial tutorials/guiWithCINT.C into a CMake project. The tutorial opened with root works fine.

However, in the CMake version, it only works if I remove the function `prompt = ((TRint*)gROOT->GetApplication())->GetPrompt()`, otherwise it gives an error. Has someone an idea on how to avoid this error without needing to remove this function?

Another issue I have seen is that the ‘X’ of the window does not call CloseWindow any more in the standalone version, while in the other it does.

Attached are my project files.  
[CMakeLists.txt](https://root-forum.cern.ch/uploads/short-url/39sMtEgPFFZndsiNQl7YIfbLy7.txt) (993 Bytes) [main.cxx](https://root-forum.cern.ch/uploads/short-url/i5bb3d5iFpQuyo3d6wqBkxamCdt.cxx) (429 Bytes) [MyTerminal.cxx](https://root-forum.cern.ch/uploads/short-url/wEpMRBvWCMWRj3mQL4Vaa3EzF1O.cxx) (3.2 KB) [MyTerminal.h](https://root-forum.cern.ch/uploads/short-url/fXpZVQ91cfcqi0Qorp66DodwaJv.h) (1.6 KB)

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [February 9, 2021, 6:37pm UTC](https://root-forum.cern.ch/t/standalone-root-terminal-cling-interpreter-in-c-cmake-project/43464/2 "2021-02-09T18:37:39Z")

</div>

Ok, it looks like the class TGCommandPlugin takes care already of the first error:

```auto
TString sPrompt = "root []";
TApplication *app = gROOT->GetApplication();
if (app->InheritsFrom("TRint"))
    sPrompt = ((TRint*)gROOT->GetApplication())->GetPrompt();

```

Still not sure about the second error (‘X’ button not working)

---

<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:** [February 9, 2021, 7:26pm UTC](https://root-forum.cern.ch/t/standalone-root-terminal-cling-interpreter-in-c-cmake-project/43464/3 "2021-02-09T19:26:49Z")

</div>

Hi @ferhue - regarding the first issue, I suspected something along these lines, glad you found that one out!

I have invited @bellenot to have a look at the second issue you mention.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [February 10, 2021, 7:28am UTC](https://root-forum.cern.ch/t/standalone-root-terminal-cling-interpreter-in-c-cmake-project/43464/4 "2021-02-10T07:28:19Z")

</div>

Remove this line (in `MyTerminal.h`):

```auto
    RQ_OBJECT("MyTerminal") ///< for classes not derived from TQObject, RQ_OBJECT macro should be used

```

This macro is for classes not derived from `TQObject` (as mentioned in the comment 😉 )

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [February 10, 2021, 8:28am UTC](https://root-forum.cern.ch/t/standalone-root-terminal-cling-interpreter-in-c-cmake-project/43464/5 "2021-02-10T08:28:21Z")

</div>

Ahh, well seen, solved! Thanks :).
