Makefile:(.text + 0x20):未定义对“ main” collect2的引用:错误:ld返回1退出状态

时间:2018-07-17 13:33:18

标签: c++ makefile root-framework

我对Makefile有疑问。也许问题是链接器,但我不能 找到错误。在某个时刻(CXX) $(CXXFLAGS) $(LDFLAGS) $^ $(ROOTLIBS) -o @

(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Makefile:65: recipe for target 'doMyAnalysisHeavyIon' failed
make: *** [doMyAnalysisHeavyIon] Error 1

Makefile

  1 all: libs programs
  2 
  3 libs: HxSimParticle_cxx.so HxSimEvent_cxx.so
  4 
  5 programs  = doMyAnalysisHeavyIon
  6 
  7 #LHAPDF    = LHAPDF-6.1.6
  8 PYTHIA8   = /home/andre/pythia8235
  9 HXPATH    = /home/andre/pythia8235/examples/Analysis
 10 
 11 # define compiler/linker flags
 12 CXX       = g++
 13 
 14 CXXFLAGS  = -O3 -Wall -fPIC
 15 CXXFLAGS += $(shell root-config --cflags)
 16 CXXFLAGS += $(shell fastjet-config --cxxflags)
 17 CXXFLAGS += -I$(HXPATH)
 18 
 19 #LDFLAGS   = -O3
 20 LDFLAGS   = -O3 -Wl,-rpath,'$(HXPATH)'
 21 LDFLAGS  += $(shell root-config --ldflags)
 22 #LDFLAGS  += -Wl,-rpath,$(PYTHIA8)/lib/
 23 #LDFLAGS  += -Wl,-rpath,$(HXPATH)/
 24 
 25 SOFLAGS   = -shared
 26 
 27 ROOTLIBS  = $(shell root-config --libs --glibs --evelibs)
 28 #ROOTLIBS += -lEG -lGui -lASImage -lASImageGui
 29 
 30 #PDFLIBS   = $(shell ${LHAPDF}/install/bin/lhapdf-config --libs)
 31 #P8LIBS     = $(shell $(PYTHIA8)/bin/pythia8-config --libs)
 32 
 33 #HXLIBS    = $(HXPATH)/HxSimParticle_cxx.so $(HXPATH)/HxSimEvent_cxx.so
 34 
 35 PROGRAMS = doMyAnalysisHeavyIon
 36 
 37 # compile/link HxSimEvent
 38 HxSimEvent_cxx.so: HxSimEventDict.o HxSimEvent.o HxSimParticleDict.o HxSimParticle.o
 39         $(CXX) $(SOFLAGS) $(LDFLAGS) $^ $(ROOTLIBS) -o $@ 
 40 
 41 HxSimEvent.o: HxSimEvent.cxx
 42         $(CXX) $(CXXFLAGS) -c $^ -o $@ 
 43 
 44 HxSimEventDict.o: HxSimEventDict.cxx
 45         $(CXX) $(CXXFLAGS) -c $^ -o $@ 
 46 
 47 HxSimEventDict.cxx: HxSimEvent.h HxSimEventLinkDef.h
 48         rootcint -f $@ -c $(CXXFLAGS) -p $^
 49 
 50 # compile/link HxSimParticle
 51 HxSimParticle_cxx.so: HxSimParticleDict.o HxSimParticle.o
 52         $(CXX) $(SOFLAGS) $(LDFLAGS) $^ $(ROOTLIBS) -o $@ 
 53 
 54 HxSimParticle.o: HxSimParticle.cxx
 55         $(CXX) $(CXXFLAGS) -c $^ -o $@ 
 56 
 57 HxSimParticleDict.o: HxSimParticleDict.cxx
 58         $(CXX) $(CXXFLAGS) -c $^ -o $@ 
 59 
 60 HxSimParticleDict.cxx: HxSimParticle.h HxSimParticleLinkDef.h
 61         rootcint -f $@ -c $(CXXFLAGS) -p $^
 62 
 63 # compile/link doMyAnalysisHeavyIon 
 64 doMyAnalysisHeavyIon: doMyAnalysisHeavyIon.o HxSimEvent_cxx.so HxSimParticle_cxx.so
 65         $(CXX) $(CXXFLAGS) $(LDFLAGS) $^ $(ROOTLIBS) -o @
 66 
 67 doMyAnalysisHeavyIon.o: doMyAnalysisHeavyIon.C
 68         $(CXX) $(CXXFLAGS) -c $^ -o $@
 69 
 70 .PHONY: clean distclean
 71 
 72 # remove object files
 73 clean:
 74         @rm -f *.o
 75 
 76 # remove objects, libraries and dicts
 77 distclean: clean
 78         @rm -f *.so *Dict.* $(PROGRAMS)

2 个答案:

答案 0 :(得分:1)

在构建可执行链接程序(Site Name: Aria Dn Name: Aria WL: Meters (m) River Name: Ben DL: Meters (m) Basin Name: GAN HFL: 49.4 Meters (m) Div Name: LGD-I HFL date: 14-08-2017 PRESENT WL Date: 17-07-2018 12:00 Value: 45.43 Meters (m) Trend: Steady CUMULATIVE DAILY RF Date: 17-07-2018 08:30 Value: 0.0 Milimiters (mm) NO FORECAST )时,正在寻找ld来将其用作调用/启动程序的功能。最可能的原因是:

  • 您忘记了在定义main()的对象中编译源代码/链接。通常,我希望您将它与Makefile内容一起放在main中。但是,它被列为编译并链接到doMyAnalysisHeavyIon.C的先决条件。
  • 是否存在拼写错误(可能是大写字母?),导致在此找不到doMyAnalysisHeavyIon? (假设它确实没有完全丢失?结果应该是可执行文件还是库?)

答案 1 :(得分:0)

第65行缺少美元符号:

 $(CXX) $(CXXFLAGS) $(LDFLAGS) $^ $(ROOTLIBS) -o $@

我不确定这是否是您的问题。请显示doMyAnalysisHeavyIon.C的内容,尤其是它是否包含main以及main是否是正确的命名空间。它必须在名称空间的顶层,并定义为int main(int argc, char* argv[]) {