Compilation problem of stand alone program


I just installed the new ubutu (11.10) and the version 5.32. of ROOT. I get problems in compiling a simple C++ “hello world” if I include for example a TH1F.h. In this case I get a “__static_initialization_and_destruction_0” error.

I explain all the steps I have done in the following:
I installed Ubuntu 11.10
I installed all prerequisites Ubuntu 9, 10 and 11
Then download root, unpack it and do:

cd root
. bin/

Then I do

export ROOTSYS=$HOME/root
export PATH=$PATH:$ROOTSYS/bin

CINT works fine. I can load and execute macro. But I cannot use my Makefile which was always working on previous versions and also on MAC. My Makefile is:

CXX = g++
LD = g++

OS_NAME:=$(shell uname -s | tr A-Z a-z)
ifeq ($(OS_NAME),darwin)

LDFLAGS := $(shell root-config --libs --glibs) -L$(LIBDIR) 
CPPFLAGS := $(shell root-config --cflags) -I$(INCDIR)


TARGET = test

SRC = main.cpp

OBJ = $(SRC:.cpp=.o) 

all : $(TARGET)

$(TARGET) : $(OBJ)

%.o : %.cpp
	$(CXX) $(CPPFLAGS) -c $< -o $@

clean :
	rm -f *.o $(TARGET)

with the simple main.cpp:

#include <iostream>
#include <TH1F.h>
using namespace std;
int main(int argc, char *argv[])
	cout<<"Hello world"<<endl;
        return 0;

when I compile I get this :

user@ubuntu:~/Work/code/test$ make
g++ -pthread -m64 -I/home/user/root/include -I/usr/include -g -L/home/user/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -L/home/user/root/lib -lGui -L/usr/lib  main.o  -o test
main.o: In function `__static_initialization_and_destruction_0':
/home/user/root/include/TVersionCheck.h:34: undefined reference to `TVersionCheck::TVersionCheck(int)'
collect2: ld a retourné 1 code d'état d'exécution
make: *** [test] Erreur 1

I have no idea where the problem is. Any help would be great!
Thank you

Try the attached Makefile.
Also … use either: export ROOTSYS=$HOME/root export PATH=$ROOTSYS/bin:$PATH export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH … or better … simply execute: source $HOME/root/bin/
Makefile.txt (581 Bytes)

Hi Pepe Le Pew,

thank you very much, this is working fine now!!
However I still don t understand why my procedure didn’t work. It was working in previous version of ubuntu and/or root. Is it the new Ubuntu that makes problem?

Thanks again.

See also: [url]Linking problem to