Compiling C++ linking in ROOT under SuSe 8

Hi!
I am trying to make a minimal program just to test that compiling c++ and linking in ROOT works on my system (intel P4, SuSe linux 8.x) …which it doesn’t so far. I use the makefile below, and get the error also shown below. What is -lRoot, and why can’t the linker find it?

kindest regards,
Axel

linux:/opt/root/AXEL/examples # make
g++ -O histo-l.o -L/opt/root/lib -lRoot -lCint -lm -o histo-l
/usr/lib/gcc-lib/i486-suse-linux/3.2/…/…/…/…/i486-suse-linux/bin/ld: cannot find -lRoot
collect2: ld returned 1 exit status
make: *** [histo-l] Error 1

######################

Edit this part

######################

ROOTSYS = /opt/root
CXX = g++
LD = g++

#############################

Do NOT edit this part

#############################

CXXFLAGS = -O -w -qnoro -qnoroconst -qmaxmem=-1 -I$(ROOTSYS)/include
LDFLAGS = -g
ROOTLIBS = -L$(ROOTSYS)/lib -lRoot -lCint
LIBS = $(ROOTLIBS) -lm
LIBSALL = $(ROOTLIBS) -lXm -lXt -lX11 -lm -lPW -lcurses

histo-l: histo-l.o
$(LD) $(LDFLAGS) histo-l.o $(LIBS) -o histo-l

.C.o:
$(CXX) $(CXXFLAGS) -c $<

Instead of -lRoot try -lCore.

– Fons

Hi,
and thanks for your helpful suggestion! The previous complaint from the linker disappeared. However, it still gives a complaint beyond my understanding, which is show below. Again, very grateful for suggestions. Below the compile/link output I have also included the program for reference.

kindest regards,
Axel

linux:/opt/root/AXEL/examples # make
g++ -O histo-l.o -L/opt/root/lib -lCore -lCint -lm -o histo-l
histo-l.o: In function main': histo-l.o(.text+0x77): undefined reference toTH1F::TH1F[in-charge](char const*, char const*, int, double, double)‘
histo-l.o(.text+0xbe): undefined reference to TH2F::TH2F[in-charge](char const*, char const*, int, double, double, int, double, double)' /opt/root/lib/libCint.so: undefined reference todlerror’
/opt/root/lib/libCore.so: undefined reference to dladdr' /opt/root/lib/libCint.so: undefined reference todlclose’
/opt/root/lib/libCint.so: undefined reference to dlopen' /opt/root/lib/libCint.so: undefined reference todlsym’
collect2: ld returned 1 exit status
make: *** [histo-l] Error 1

#include “TROOT.h”
#include “TFile.h”
#include “TH1.h”
#include “TH2.h”
#include “TProfile.h”
#include “TNtuple.h”
#include “TRandom.h”

#ifdef SC
long G__globalvarpointer; // only for Symantec linker
#endif

int Error;

main(int argc, char **argv)
{

TROOT simple(“simple”,"");

TFile hfile(“hsimple.root”,“RECREATE”);

TH1F *hx = new TH1F(“hx”,“1-dim”,100,-4,4);
TH2F *hxy = new TH2F(“hxy”,“2-dim”,40,-4,4,40,-4,4);

/*** 3-dim histogram is NOT working (?!) ***/
// TH3F *hxyz = new TH3F(“hxyz”,“3-dim”,20,-4,4,20,-4,4,20,-4,4);

gRandom->SetSeed();

float x, y, z;

for (int i=0; i<100; i++) {

 gRandom->Rannor(x,y);
 z = x;

 float random = gRandom->Rndm(1);

 hx->Fill(x);
 hxy->Fill(x,y);

 /*** 3-dim histogram is NOT working (?!) ***/
 // hxyz->Fill(x,y,z);

}

/*** Save all objects in this file ***/
hfile.Write();

/*** Close the file ***/
hfile.Close();

return 0;

}

You are missing “-ldl” in your link procedure.
You can use the small utility “root-config” in $ROOTSYS/bin to see the list of recommended options to compile or/and link;
root-config --libs
will show you the list of link options in a machine independent format.
You can also include root-config as

g++ -O histo-l.o root-config --libs -o histo-l

Rene

Thanks for again swiftly finding the solution! The compilation and linking now gives no error messages. The executable is generated.

However, when I try to run it (see below), it can not find the shared libraries (complains only about the first in the list to the linker, but when I change the order the same error repeats for the new lib first in the list). The ROOTLIBS and ROOTSYS variables are set to /opt/root/lib and /opt/root respectively, and in /opt/root/lib I do indeed have the files to be linked (as e.g. the libCint.so shown in the error below).

Grateful for advice, which if I’m lucky could be the last needed on this issue…

cheers,
Axel

linux:/opt/root/AXEL/examples # ./histo-l
./histo-l: error while loading shared libraries: libCint.so: cannot open shared object file: No such file or directory

Hi!
The problem I previously mentioned seems to change into another problem if I include the -shared flag in the linker. Then, the “only” problem is that I get a segmentation fault - even if I run an empty program! I.e. a main() with no content. Grateful for any ideas/suggestions.

with kindest regards,
Axel

Check that $ROOTSYS/lib (or it equivalent) is list in LD_LIBRARY_PATH

Cheers,
Philippe

Hi!
By using the tests and tutorials I made a file that can compile. But it seems that an empty c++ program somehow generates a segmentation fault. Anyway, thanks for all the help, now I can continue to build on the sample files.

regards,
Axel