libTree.so: undefined reference to...?

Recently I installed ROOT_v5.22 on my laptop with gcc version 4.3.2.

When I am compiling our simulation code (which is combination of Geant4 and ROOT), it gives the following error:

Linking ActarSim ...
root_v5.22/lib/libTree.so: undefined reference to `TThread::TThread(char const*, void* (*)(void*), void*, TThread::EPriority)'
root_v5.22/lib/libTree.so: undefined reference to `TThread::Exists()'
root_v5.22/lib/libTree.so: undefined reference to `TThread::SelfId()'
root_v5.22/lib/libTree.so: undefined reference to `TThread::Join(void**)'
root_v5.22/lib/libTree.so: undefined reference to `TThread::Run(void*)'
root_v5.22/lib/libTree.so: undefined reference to `TMutex::TMutex(bool)'
root_v5.22/lib/libTree.so: undefined reference to `TCondition::TCondition(TMutex*)'
root_v5.22/lib/libHtml.so: undefined reference to `TThread::TThread(void* (*)(void*), void*, TThread::EPriority)'
root_v5.22/lib/libTree.so: undefined reference to `TThread::SetCancelOn()'
root_v5.22/lib/libTree.so: undefined reference to `TCondition::Wait()'
root_v5.22/lib/libTree.so: undefined reference to `TThread::SetCancelDeferred()'
collect2: ld returned 1 exit status
make: *** [/home/dypang/g4work/bin/Linux-g++/ActarSim] Error 1

I have no idea how to solve this problem.

Please tell me what other information you need me to provide.

Thanks in advance.

Hi,

Are you linking your example against libThread?
Alternatively you might be able to drop the direct linking of libTree and libHtml which can now be autoloaded when needed.

Cheers,
Philippe.

[quote=“pcanal”]Hi,

Are you linking your example against libThread?
Alternatively you might be able to drop the direct linking of libTree and libHtml which can now be autoloaded when needed.

Cheers,
Philippe.[/quote]

Thanks for your suggestion.

I found the problem was because in GNUmakefile there is one line:

ROOTLIBS      := $(filter-out -lThread,$(ROOTLIBS))

removing of this line solves this problem.

This problem comes back again! Exactly the same problem. I don’t know what I have done. I should have not touched the code…

[quote]Exactly the same problem. [/quote]Most likely with the same cause, i.e. “not linking with libThread”; either you inadvertently remove your change to the makefile or your makefile has yet another way of producing this executable.

Philippe

Thanks for reply.

Could you please help to have a look at the GNUmakefile of my code. I really don’t see any problem in it.

By the way, on my desktop which has ROOT v5.14 installed, I don’t have this problem with the same code.

I have this problem on my laptop which has ROOT v5.22 installed.

One amazing thing is that It has once worked on my laptop… I just really don’t remember what I have done this morning. I am sure I did not do anything significant (I wish I could…)

# --------------------------------------------------------------
# GNUmakefile for ACTARSIM module.  
# Following the examples module GNUMakefile.
# ACTARSIM
# --------------------------------------------------------------

name := ActarSim
G4TARGET := $(name)
G4EXLIB := true

G4TMPDIR = $(G4TMP)/$(G4SYSTEM)/$(name)

ifndef G4INSTALL
  G4INSTALL = ../../..
endif

.PHONY: all
all: lib bin sharedlib

include $(G4INSTALL)/config/binmake.gmk

#######  ROOT includes and libs (in case G4UIROOT is not defined) ########
ifndef INC_ROOT
   CPPFLAGS += $(shell $(ROOTSYS)/bin/root-config --cflags) -lRIO
endif
ifndef LOAD_ROOT
   ROOTLIBS      = $(shell $(ROOTSYS)/bin/root-config --glibs) -lRIO -lMinuit -lHtml
   ROOTLIBS      := $(filter-out -lNew,$(ROOTLIBS))
#   ROOTLIBS      := $(filter-out -lThread,$(ROOTLIBS))
   ROOTLIBS      := $(filter-out -lpthread,$(ROOTLIBS))
   INTYLIBS      += $(ROOTLIBS)
endif
##########################################################################

visclean:
	rm -f g4*.prim g4*.eps g4*.wrl
	rm -f .DAWN_*

outclean:
	rm -f *~ *.rndm simFile.root

######################## ROOT dictionary ################################
#Inspired in Isidro Gonzalez GNUmakefile in his G4UIROOT interface!!

# Root Headers
ROOTHDRS := ActarSimData.hh ActarSimTrack.hh ActarSimSimpleTrack.hh ActarSimSciHit.hh ActarSimSilHit.hh ActarSimPrimaryInfo.hh ActarSimBeamInfo.hh
ROOTHDRSWITHPATH := $(patsubst %.hh,include/%.hh,$(ROOTHDRS))

# Make library depend on the root dictionary object file also
$(G4LIBDIR)/lib$(name).$(SHEXT): $(G4TMPDIR)/obj.last \
			         $(G4TMPDIR)/ActarSimDict.o

$(G4TMPDIR)/ActarSimDict.o: src/ActarSimDict.cc $(G4TMPDIR)/ActarSimDict.d

# Produce the dictionary file
src/ActarSimDict.cc: $(ROOTHDRSWITHPATH) \
		     src/ActarSimLinkDef.hh \
		     $(ROOTSYS)/include/RVersion.h
	@echo Making Root Dictionary...
ifdef CPPVERBOSE
	cd src; rootcint -f ActarSimDict.cc -c -p -I../include $(ROOTHDRS) ActarSimLinkDef.hh
else
	@cd src; rootcint -f ActarSimDict.cc -c -p -I../include $(ROOTHDRS) ActarSimLinkDef.hh
endif

# Clean up root dictionary
cleandict: src/ActarSimDict.cc
	@echo Removing Root dictionary and shared library...
	@rm -f src/ActarSimDict.*
	@rm -f $(G4TMPDIR)/ActarSimDict.*
	@rm -f actarsim.sl

# Make clean target clean de dictionary files...
#clean: cleandict

################ A SHARED LIBRARY WITH THE DATA DEFINITION FOR ROOT ######
#Hector Alvarez GNUmakefil: TESTING A SHARED LIBRARY ONLY FOR ROOT

CXXSHAREDFLAGS	= -g -I$(ROOTSYS)/include
LDSHAREDFLAGS   = -g
LDSHARED        = g++

SHAREDLIB       = actarsim.sl

SHAREDLIBHDRS	= $(ROOTHDRS) ActarSimDict.hh
SHAREDSRCS      = $(SHAREDLIBHDRS:.hh=.cc)
SHAREDOBJS	= $(SHAREDSRCS:.cc=.o)
SHAREDOBJSWITHPATH := $(patsubst %.o,$(G4TMP)/$(G4SYSTEM)/$(name)/%.o,$(SHAREDOBJS))

sharedlib:	$(SHAREDLIB)

$(SHAREDLIB):
		echo "Linking $(SHAREDLIB) ..."
		/bin/rm -f $(SHAREDLIB)
		$(LDSHARED) -Wl,-soname, -shared -o $(SHAREDLIB) $(SHAREDOBJSWITHPATH)
##$(CXX) -Wl,-soname,$(@F) -shared -o $$libdir/$(@F) $(INTYLIBS) *.o
		chmod 555 $(SHAREDLIB)
		echo "done"

It turns out that it is GEANT4 who is responsible to this problem.

When I use Geant4.9.1.p03 instead of the latest Geant4.9.2, with ROOT_v5.22, I have no problem to compile my simulation code.

But I don’t know why, since it is geant4 which has problem, it reports problem all with ROOT’s stuff, for example:

/home/dypang/programs/root/root_v5.22/lib/libTree.so: undefined reference to `TThread::Exists()'
/home/dypang/programs/root/root_v5.22/lib/libTree.so: undefined reference to `TThread::SelfId()'
/home/dypang/programs/root/root_v5.22/lib/libTree.so: undefined reference to `TThread::Join(void**)'
/home/dypang/programs/root/root_v5.22/lib/libTree.so: undefined reference to `TThread::Run(void*)'
/home/dypang/programs/root/root_v5.22/lib/libTree.so: undefined reference to `TMutex::TMutex(bool)'
/home/dypang/programs/root/root_v5.22/lib/libTree.so: undefined reference to `TCondition::TCondition(TMutex*)'

Hi,

I see

so I am guessing that this Geant4 makefile fragment is messing with your makefile variable (and stripping out the libThread from your list of libraries).

Cheers,
Philippe.