PIC编译 - 错误:在创建共享对象时,不能使用针对“命中的vtable”的重定位R_X86_64_32S;用-fPIC重新编译

时间:2012-12-12 10:41:31

标签: 32bit-64bit relocation fpic

我是Linux的新手,我在编译一个在32位机器上运行良好的make文件时遇到了麻烦。我没有写这个程序,但我需要它来使用它的功能。我的机器是64位,我收到以下消息错误:

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

我一直试图通过使用这个网站解决问题,但我没有让程序工作...... http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3 我不习惯makefile,这就是为什么我没有设法正确修改makefile到PIC编译共享库。我在全球范围内添加了标志'export CXXFLAGS = $ CXXFLAGS -fPIC',但它没有用。我完全迷失了。

以下是make文件(两个make文件和一个调用它们的文件)。

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

希望有人能帮助我。 提前致谢!! 丹尼尔

1 个答案:

答案 0 :(得分:1)

您的makefile正在使用$CFLAGS,而不是$CXXFLAGS。 您必须全局(-fPIC)或在makefile中的右侧添加export CXXFLAGS=$CXXFLAGS -fPIC(例如CFLAGS = $(shell $(ROOTCONFIG) --cflags) -I../pmtTools)。

从错误消息中,我想只添加到第二个makefile就足够了。