AddExec() in a compiled code

Dear ROOTers,

My apologizes in advance, because this subject has been already discussed in previous talks “here” and “here 2”, but I did not really understand what might be wrong in my case. First, I made a macro and then compiled with CINT as “.L macros/CSpec.C++” but in order to make it cleaner and add other features I would need to go for a compiled version.

You can find in attachment an example of something that I want to do:

  1. Draw a TCanvas
  2. Run an AddExec on it without to quit

CSpec.cxx (4.1 KB)
CMakeLists.txt (3.7 KB)

In order to compile and produce the executable:

cmake …/

The AddExec is just supposed to draw a vertical under the mouse cursor when typing “b”.

As I red in previous talks, I declared the function as static void myexec(), but when I try to interact with the TCanvas, I get the following error:

input_line_82:2:3: error: use of undeclared identifier ‘myexec’

I also tried to remove the line:


and modify the function void exec() as:

in order to make the job of AddExec, but it cannot interact with the TCanvas and nothing happens.

Any comments and ideas are very welcome.


If your function is in a different file, declaring it static will make it invisible to other translation units. That’s probably why the error you see is that the function is not found. The static keyword has different meanings in different contexts. In file scope, it has the same meaning as putting the function inside an unnamed namespace. TLDR: Just remove static when declaring your function, and it should work.


First of all thank you for your reply.

By removing static, the problem remains the same while moving the mouse on the TCanvas:

input_line_35:2:3: error: use of undeclared identifier ‘myexec’
input_line_38:2:3: error: use of undeclared identifier ‘myexec’
input_line_40:2:3: error: use of undeclared identifier ‘myexec’


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