2
votes

I'm newbie with Linux and I'm having trouble with compiling a make file which works well in a 32-bit machine. I didn't write this program but I need it to work to use its functionalities. My machine is 64-bit and I get the following message error:

cd pmtTools;    make 
make[1]: Entering directory `/home/daniel/Documents/Master_thesis/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysis/pmtTools'
g++ -shared  -L/home/root/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -o libPmtTools.so hit.o event.o waveform.o readLeCroyBinary.o pmtToolsDict.o
/usr/bin/ld: hit.o: relocation R_X86_64_32S against `vtable for hit' can not be used when making a shared object; recompile with -fPIC
hit.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [libPmtTools.so] Error 1
make[1]: Leaving directory `/home/daniel/Documents/Master_thesis/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysis/pmtTools'
make: *** [all] Error 2

I've been trying to solve the problem by using this website but I don't get the program to work... http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3 I'm not used to makefiles and that's why I don't manage to modify the makefiles properly to PIC compile the shared libraries. I added globally the flag 'export CXXFLAGS=$CXXFLAGS -fPIC' but it didn't work. I'm just completely lost.

Here are the make files (two make files and one which calls them).

ROOTCONFIG = $(ROOTSYS)/bin/root-config
ROOTCINT = $(ROOTSYS)/bin/rootcint
DOXYGEN = doxygen

CXX = $(shell $(ROOTCONFIG) --cxx)
LD = $(shell $(ROOTCONFIG) --ld)

CFLAGS = $(shell $(ROOTCONFIG) --cflags) 
LIBS  = $(shell $(ROOTCONFIG) --libs)
SOFLAGS = -shared 

CINTSRCS = event.cc hit.cc
CINTINCS = event.h hit.h

OBJS = hit.o event.o waveform.o readLeCroyBinary.o pmtToolsDict.o

LIBPMTTOOLS = libPmtTools.so

all: $(LIBPMTTOOLS)
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/Documents/Master_thesis/data_Daniel-Thomas/photondet/trace/PMTSignalsAnalysis/pmtTools

$(LIBPMTTOOLS): $(OBJS)
    $(LD) $(SOFLAGS) $(LIBS) -o $@ $(OBJS)

%.o: %.cc
    $(CXX) $(CFLAGS) -c -o $@ $<

pmtToolsDict.cc: $(CINTSRCS) $(CINTINCS) pmtToolsLinkDef.h
    @echo "Generating dictionary pmtToolsDict..."
    $(ROOTCINT) -f pmtToolsDict.cc -c -p $(CINTINCS) pmtToolsLinkDef.h

clean:
    rm -f pmtToolsDict.cc pmtToolsDict.h $(LIBPMTTOOLS) $(OBJS)

dox:
    rm -rf html
    $(DOXYGEN) pmtTools.dox

-----------------------------------------2 --------------------

ROOTCONFIG = $(ROOTSYS)/bin/root-config

CXX = $(shell $(ROOTCONFIG) --cxx)
LD = $(shell $(ROOTCONFIG) --ld)

CFLAGS = $(shell $(ROOTCONFIG) --cflags) -I../pmtTools 
LIBS  = $(shell $(ROOTCONFIG) --libs)# -L../pmtTools -lpmtTools

OBJS = analysis.o
SHARED = ../pmtTools/libPmtTools.so
EXE = analysis.exe

all:  $(EXE)

$(EXE): $(OBJS) $(SHARED)
    $(LD) $(LIBS) -o $@ $(OBJS) $(SHARED)

$(SHARED):
    cd ../pmtTools; make

%.o: %.cxx
    $(CXX) $(CFLAGS) -c -o $@ $<

test: test.cxx $(SHARED)
    $(CXX) $(CFLAGS) -c -o test.o test.cxx
    $(LD) $(LIBS) -o test.exe test.o $(SHARED)

clean:
    rm -f $(EXE) $(OBJS) test.o test.exe

----------------------3-------------------------

 all:
    cd pmtTools;    make 
    cd analysis;    make 

 clean:
    cd pmtTools;    make clean
    cd analysis;    make clean

Hope that someone can help me. Thanks in advance!! Daniel

1

1 Answers

1
votes

Your makefile is using $CFLAGS, not $CXXFLAGS. You must add -fPIC either globally (export CXXFLAGS=$CXXFLAGS -fPIC) or to the right line in the makefiles (e.g. CFLAGS = $(shell $(ROOTCONFIG) --cflags) -I../pmtTools).

From the error message, I guess adding only to the second makefile may be enough.