Re: TControlBar in standalone program

From: Rene Brun <brun_at_pcroot.cern.ch>
Date: Tue, 26 Apr 2005 11:26:22 +0200 (MEST)


Hi Guennadi,

Your second case cannot work. The linker will not load myfunc from the archive library in memory if nobody references your function.

Rene Brun

On Tue, 26
Apr 2005, Guennadi Pospelov wrote:

>
> Hello,
> I am trying to call function myfun() from TControlBar in standalone program
> and I have error message
> "Function myfun() is not defined in current scope FILE:(tmpfile) LINE:1"
> if function and dictionary is inside static library. If everything compilled
> together - all works well.
>
> Could you please help me with it?
>
> Many thanks in advance,
> Guennadi.
>
>
> Working example, everything together.
> :::::::::: main.cc :::::::::::
> int main()
> {
> TApplication theApp("theapp",0,0);
> TControlBar *bar = new TControlBar("vertical", "KEmcDrawPanel",10,10);
> bar->AddButton("myfun","myfun()","nothing special");
> bar->Show();
> theApp.Run();
> return 0;
> }
> :::::::::: myfun.h :::::::::::
> extern void myfun();
> :::::::::: myfun.cc :::::::::::
> void myfun() { printf("button pressed!\n"); }
> :::::::::: myfunLinkDef.h :::::::::::
> #ifdef __CINT__
> #pragma link off all globals;
> #pragma link off all classes;
> #pragma link off all functions;
> #pragma link C++ function myfun;
> #endif
> :::::::::: link script :::::::::::
> rootcint -f myfunDict.cc -c myfun.h myfunLinkDef.h
> g++ `root-config --cflags` main.cc myfun.cc myfunDict.cc -o example1
> `root-config --libs`
>
> NOT working example - "myfun() is not defined in current scope"
> everything the same except link script
> ::: link script :::
> rootcint -f myfunDict.cc -c myfun.h myfunLinkDef.h
> g++ `root-config --cflags` -c main.cc -o main.o
> g++ `root-config --cflags` -c myfun.cc -o myfun.o
> g++ `root-config --cflags` -c myfunDict.cc -o myfunDict.o
> ar lruv libmyfun.a myfun.o myfunDict.o
> g++ -o example2 main.o -L./ -lmyfun `root-config --libs`
>
> All files in the attachment.
> ROOT 4/00/08, SLC3
>
>
Received on Tue Apr 26 2005 - 11:27:34 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:07 MET