# TClassMenuItem not connected to function

**URL:** <https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098>\
**Category:** Cling\
**Created:** [February 8, 2024, 11:34am UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098 "2024-02-08T11:34:31Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emmanuel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emmanuel/32/35652_2.png) [@Emmanuel](https://root-forum.cern.ch/u/Emmanuel)\
**Post date:** [February 8, 2024, 11:34am UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/1 "2024-02-08T11:34:31Z")

</div>

Hi,

I’m currently porting a software from root5 to root6. I’m experiencing an issue where the menuitem are not triggering the functions they are supposed to. I’m using the root API from a C++ compiled application. Menu items are declared like this in the C++ code:

```cpp
 laxmenu->AddFirst(new TClassMenuItem(
       TClassMenuItem::kPopupUserFunction,claxis,"Zoom ALL X as last","URZoomAllXAsLast",0,"TObject*",0,0));

```

The function is declared in a header file:

```cpp
void URZoomAllXAsLast(TObject* objaxis);

```

The dictionary is generated using this linkdef file:

```hpp
#pragma link C++ function URZoomAllXAsLast;

```

Using root, I’m able to call the function:

```auto
root [0] gSystem->Load("libdy_c.so")
(int) 0
root [1] URZoomAllXAsLast(0)

 ***Break*** segmentation violation

```

(Segmentation fault is expected, the function does not check for NULL argument).

But in the application, a click on the corresponding menu item does not call the function. Any idea why the function is not connected to the click event ?

Emmanuel.

---

<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:** [February 8, 2024, 11:47am UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/2 "2024-02-08T11:47:35Z")

</div>

Welcome to the ROOT forum

As it looks like a GUI (`TClassMenuItem`) (?) question I guess @bellenot might help you.

---

<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 8, 2024, 12:05pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/3 "2024-02-08T12:05:53Z")

</div>

Please provide a complete example we can try. And BTW, does the `${ROOTSYS}/tutorials/gui/customContextMenu.C` work for you?

---

<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 8, 2024, 12:30pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/4 "2024-02-08T12:30:54Z")

</div>

So I just added these lines in `${ROOTSYS}/tutorials/gui/customContextMenu.C`

```auto
   n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,
                          "Zoom ALL X as last","URZoomAllXAsLast",0,"TObject*",2);
   l->AddFirst(n);

```

with `URZoomAllXAsLast` being:

```auto
void URZoomAllXAsLast(TObject* objaxis)
{
   printf("URZoomAllXAsLast %tx\n",(intptr_t)objaxis);
}

```

And it works just fine:

```auto
C:\root-dev\build\x64\debug\tutorials\gui>root -l customContextMenu.C
root [0]
Processing customContextMenu.C...
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
root [1] URZoomAllXAsLast 1ba8ab55d40

```

---

<div class="post-metadata">

**Author:** ![Emmanuel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emmanuel/32/35652_2.png) [@Emmanuel](https://root-forum.cern.ch/u/Emmanuel)\
**Post date:** [February 8, 2024, 1:44pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/5 "2024-02-08T13:44:39Z")

</div>

Thanks. I will try to come up with a simple project exhibiting the issue.

Regarding your answer, please note my issue happens in a compiled application, not a script launched using root.

---

<div class="post-metadata">

**Author:** ![Emmanuel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emmanuel/32/35652_2.png) [@Emmanuel](https://root-forum.cern.ch/u/Emmanuel)\
**Post date:** [February 8, 2024, 3:22pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/6 "2024-02-08T15:22:16Z")

</div>

> [@bellenot](#):
>
> Please provide a complete example we can try. And BTW, does the `${ROOTSYS}/tutorials/gui/customContextMenu.C` work for you?

Here is a simple example, using customContextMenu.c as a starting point: https:/ /github.com/EmmanuelP/root-test (Broken URL, new users are not allowed to post links ☹ )

Callbacks are not called in the compiled application, but it works when the menus are built from the root interpreter.

---

<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 8, 2024, 3:32pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/7 "2024-02-08T15:32:07Z")

</div>

OK, thanks. It will take a bit of time, I work on Windows and obviously `meson.build` (whatever it is) will not work. I’ll keep you informed

---

<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 8, 2024, 4:03pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/8 "2024-02-08T16:03:25Z")

</div>

OK, I can reproduce the issue. Investigating…

---

<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 9, 2024, 3:20pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/9 "2024-02-09T15:20:20Z")

</div>

It looks like an interpreter issue. If I declare it this way:

```auto
   gInterpreter->Declare("void URZoomAllXAsLast(TObject* objaxis) { printf(\"URZoomAllXAsLast %zx\\n\",(intptr_t)objaxis);}");

```

It works… So I’ll have to dig into the interpreter, unless @pcanal or @Danilo has an idea…

---

<div class="post-metadata">

**Author:** ![Emmanuel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emmanuel/32/35652_2.png) [@Emmanuel](https://root-forum.cern.ch/u/Emmanuel)\
**Post date:** [February 9, 2024, 6:05pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/10 "2024-02-09T18:05:15Z")

</div>

Hi,

I played a bit with my test app. It looks like a simple include statement in `gInterpreter->Declare` is enough: [https://github.com/EmmanuelP/root-test/commit/c8d33613108d9e5e41760a63434796dae08a23b6](https://github.com/EmmanuelP/root-test/commit/c8d33613108d9e5e41760a63434796dae08a23b6).

Now all the callbacks are correctly called on a menu click.

Emmanuel.

---

<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 9, 2024, 6:07pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/11 "2024-02-09T18:07:17Z")

</div>

OK, thanks for the info, I’ll check

---

<div class="post-metadata">

**Author:** ![Emmanuel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emmanuel/32/35652_2.png) [@Emmanuel](https://root-forum.cern.ch/u/Emmanuel)\
**Post date:** [February 9, 2024, 6:13pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/12 "2024-02-09T18:13:34Z")

</div>

Another thing I have tried, that may give a hint about the interpreter issue, is a proxy function: [https://github.com/EmmanuelP/root-test/commit/f66078f85ef0a2fb731bb9a5f5c0df21136e5bbd](https://github.com/EmmanuelP/root-test/commit/f66078f85ef0a2fb731bb9a5f5c0df21136e5bbd)

But this test failed with the following error after a click on the menu item:

```auto
IncrementalExecutor::executeFunction: symbol '_Z16URZoomAllXAsLastP7TObject' unresolved while linking [cling interface function]!
You are probably missing the definition of URZoomAllXAsLast(TObject*)
Maybe you need to load the corresponding shared library?

```

---

<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 9, 2024, 6:16pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/13 "2024-02-09T18:16:57Z")

</div>

Well, in CMake, one needs

```auto
set_target_properties(libCallbacks PROPERTIES ENABLE_EXPORTS 1)

```

but with your system, I can’t tell

---

<div class="post-metadata">

**Author:** ![Emmanuel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emmanuel/32/35652_2.png) [@Emmanuel](https://root-forum.cern.ch/u/Emmanuel)\
**Post date:** [February 9, 2024, 6:45pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/14 "2024-02-09T18:45:09Z")

</div>

In the proxy test, URZoomAllXAsLast was not found due to name mangling being disabled by `extern "C"`. The proxy workaround also works if I reenable C++ name mangling in `callbacks.h`.

[https://github.com/EmmanuelP/root-test/commit/1c3380f8827a335799fc87d253715fec0b8f74e3](https://github.com/EmmanuelP/root-test/commit/1c3380f8827a335799fc87d253715fec0b8f74e3)

---

<div class="post-metadata">

**Author:** ![Emmanuel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emmanuel/32/35652_2.png) [@Emmanuel](https://root-forum.cern.ch/u/Emmanuel)\
**Post date:** [February 13, 2024, 4:30pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/15 "2024-02-13T16:30:43Z")

</div>

Hi,

> [@bellenot](#):
>
> Well, in CMake, one needs
> 
> ```auto
> set_target_properties(libCallbacks PROPERTIES ENABLE_EXPORTS 1)
> 
> ```
> 
> but with your system, I can’t tell

I’m not sure to understand, is this supposed to fix the issue about functions not found by the interpreter, or it is a comment about [https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/12?u=emmanuel](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/12) ?

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [February 27, 2024, 4:31pm UTC](https://root-forum.cern.ch/t/tclassmenuitem-not-connected-to-function/58098/16 "2024-02-27T16:31:15Z")

</div>

Closed on February 27, 2024, 4:31pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
