AddExec in compiled code (static doesn't help)

Hi. I’m trying to implement an AddExec in a class, which will create a TCanvas and do things when the mouse does things. For reasons I don’t understand, this doesn’t work, despite seeing many posts about making AddExec work in compiled code. I receive errors like:

$ ./script.x
[ canvas pops up ]
[ I move the mouse over the canvas ]
input_line_35:2:2: error: 'MyClass' is not a class, namespace, or enumeration
 MyClass::MouseEvent()

I put instructions for a MWE below. Any suggestions would be appreciated!

script:
http://www.cern.ch/tuna/mwe/script.C

include:
http://www.cern.ch/tuna/mwe/MyClass.hh

compile:
g++ -I. -fPIC -Wall -O3 -g -std=c++11 -m64 -I/usr/local/Cellar/root/6.12.04/include/root -o script.x -L/usr/local/Cellar/root/6.12.04/lib/root -lGui -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -lm -ldl script.C

run:
./script.x

I seems find in ROOT:

$ root 
   ------------------------------------------------------------
  | Welcome to ROOT 6.15/01                  https://root.cern |
  |                               (c) 1995-2018, The ROOT Team |
  | Built for macosx64 on Sep 26 2018, 10:01:38                |
  | From heads/master@v6-13-04-1416-gacc3fcb985                |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] .L MyClass.C 
root [1]  auto obj = new MyClass();
root [2]   obj->Run();
root [3] MouseEvent
MouseEvent
MouseEvent
MouseEvent
MouseEvent
MouseEvent

Hi @couet. That works for me, too. Any idea why this doesn’t run from the command line?

My original errors were found on OSX, but I just tried running also on CentOS and find the same error.

May be @pcanal would know. What you do seems correct …

Most likely because that version does not ‘teach’ Cling about MyClass (for which you would either need to generate a dictionary via rootcling or genreflex) or at least ask cling to load the header

gInterpreter->Declare("#include \"MyClass.hh\"");

Cheers,
Philippe.

Thanks @pcanal. That works.

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