Static link executable


I’m a new ROOT user and I need to compile and link my root program so to have an executable to be run on a machine which does not support root.
Can you help me?
I tried to make a makefile like this but it doesn’t really work:

roottest.o: roottest.C
g++ -I$(ROOTSYS)/include -c roottest.C
SRCFILES = roottest.C
OBJFILES = roottest.o
gcc $(OBJFILES) -o roottest $(ROOTSYSLIB)

and this is how my roottest.C looks like:

FILE *stream;
int j;
if((stream = fopen(“roottest.out”,“a+”))== NULL)
printf(“Error opening the file\n”);
printf(“Hello World!\n”);
fprintf(stream,“Hello world!\n”);
printf(“Error closing the file\n”);

If there is anything else you need to know, just let me know.

Thank you.

To generate a static module using ROOT, you need to generate libRoot.a, an archive library containing all ROOT classes. This library is created when installing ROOT from source
make static

make static generates $ROOTSYS/lib/libRoot.a as well as a static
module $ROOTSYS/bin/roota.

To build the static module, one must force the dictionaries to be loaded
in the executable from libRoot.a. An example can be found in the procedurebelow linking a static executable of geant3 with ROOT.


( [139] cat bind_gexam1a
export ROOTPROF=$HOME/rootprof/root
g++ -pg -O -c …/TGeant3/TGeant3.cxx -I$ROOTSYS/include -DWITHROOT -I…/TGeant3 -o TGeant3_prof.o
g++ -pg -O -c …/TGeant3/TGeant3f77.cxx -I$ROOTSYS/include -DWITHROOT -I…/TGeant3 -o TGeant3f77_prof.o
g++ -pg -O -c …/TGeant3/TG3Application.cxx -I$ROOTSYS/include -DWITHROOT -I…/TGeant3 -o TG3Application_prof.o
g77 -pg -O -c gexam1.F -o gexam1_prof.o
g++ -pg -O -o gexam1a gmain.cxx gexam1_prof.o -I$ROOTPROF/include -I…/TGeant3
TGeant3_prof.o TGeant3f77_prof.o TG3Application_prof.o
/usr/X11R6/lib/libXpm.a /usr/X11R6/lib/libX11.a
-L$CERNLIB -lpacklib -lg2c -lpthread -lcrypt -lm -ldl