Static link executable

Hi,

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:

ROOTSYSLIB = -L$(ROOTSYS)/lib
roottest.o: roottest.C
g++ -I$(ROOTSYS)/include -c roottest.C
SRCFILES = roottest.C
OBJFILES = roottest.o
exe: $(SRCFILES) $(OBJFILES)
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”);
for(j=0;j<1000;j++)
{
printf(“Hello World!\n”);
fprintf(stream,“Hello world!\n”);
}
if(fclose(stream))
printf(“Error closing the file\n”);
}

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

Thank you.
Dafne.

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
./configure
make
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.

Rene

(pcbrun.cern.ch) [139] cat bind_gexam1a
#!/bin/sh
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
$ROOTPROF/base/src/TROOT.o
$ROOTPROF/base/src/G__.o
$ROOTPROF/cont/src/G__
.o
$ROOTPROF/eg/src/G__.o
$ROOTPROF/g3d/src/G__
.o
$ROOTPROF/gpad/src/G__.o
$ROOTPROF/graf/src/G__
.o
$ROOTPROF/gui/src/G__.o
$ROOTPROF/hist/src/G__
.o
$ROOTPROF/histpainter/src/G__.o
$ROOTPROF/html/src/G__
.o
$ROOTPROF/matrix/src/G__.o
$ROOTPROF/meta/src/G__
.o
$ROOTPROF/minuit/src/G__.o
$ROOTPROF/net/src/G__
.o
$ROOTPROF/physics/src/G__.o
$ROOTPROF/postscript/src/G__
.o
$ROOTPROF/rint/src/G__.o
$ROOTPROF/tree/src/G__
.o
$ROOTPROF/treeplayer/src/G__.o
$ROOTPROF/unix/src/G__
.o
$ROOTPROF/x11/src/G__.o
$ROOTPROF/x3d/src/G__
.o
$ROOTPROF/geom/src/G__.o
$ROOTPROF/geompainter/src/G__
.o
$ROOTPROF/vmc/src/G__*.o
$ROOTPROF/lib/libRoot.a
$ROOTPROF/lib/libfreetype.a
TGeant3_prof.o TGeant3f77_prof.o TG3Application_prof.o
/user/brun/pythia6/libPythia6.so
/user/brun/geant3/lib/tgt_Linux/libgeant321.so
/usr/X11R6/lib/libXpm.a /usr/X11R6/lib/libX11.a
-L$CERNLIB -lpacklib -lg2c -lpthread -lcrypt -lm -ldl