Home | News | Documentation | Download

Makefile /usr/bin/ld: cannot find -l (MyClass)


#1

Hi, All.

ROOT 6.15/01  Built for linuxx8664gcc 
From heads/master@v6-13-04-536-g67ea09a

I am creating a Makefile to compile the file doMyAnalysisHeavyIon.C

Makefile:

all: doMyAnalisysHeavyIon

PROGRAMS  = doMyAnalysisHeavyIon

#LHAPDF    = LHAPDF-6.1.6
PYTHIA8   = /home/andsilva/pythia8230
HXPATH    = /home/andsilva/pythia8230/examples

# define compiler/linker flags
CXX       = g++

CXXFLAGS  = -O3 -Wall -fPIC
CXXFLAGS += $(shell root-config --cflags)
#CXXFLAGS += -I$(shell $(LHAPDF)/install/bin/lhapdf-config --incdir)
CXXFLAGS += -I$(shell $(PYTHIA8)/bin/pythia8-config --includedir)
CXXFLAGS += -I$(HXPATH)/

LDFLAGS   = -O3
LDFLAGS  += $(shell root-config --ldflags)
LDFLAGS  += -Wl,-rpath,$(PYTHIA8)/lib/
LDFLAGS  += -Wl,-rpath,$(HXPATH)/

ROOTLIBS  = $(shell root-config --glibs --libs --evelibs)
ROOTLIBS += -lEG -lGui -lASImage -lASImageGui

#PDFLIBS   = $(shell ${LHAPDF}/install/bin/lhapdf-config --libs)
P8LIBS    = $(shell $(PYTHIA8)/bin/pythia8-config --libs)

HXLIBS    = -L$(HXPATH)/ -lHxSimParticle -lHxSimEvent

# compile/link doMyAnalysisHeavyIon 
doMyAnalysisHeavyIon: doMyAnalysisHeavyIon.o
        $(CXX) $(CXXFLAGS)  $(LDFLAGS) $^ $(ROOTLIBS) $(HXLIBS) -o $@

doMyAnalysisHeavyIon.o: doMyAnalysisHeavyIon.C
        $(CXX) $(CXXFLAGS) -c $^ -o $@

.PHONY: clean distclean

# remove object files
clean:

# remove objects, libraries and dicts
distclean: clean
        @rm -f $(PROGRAMS)

Error:

$ make doMyAnalysisHeavyIon
g++ -O3 -Wall -fPIC -pthread -std=c++11 -m64 -I/home/andsilva/build/include -I/home/andsilva/pythia8230/include -I/home/andsilva/pythia8230/examples/ -c doMyAnalysisHeavyIon.C -o doMyAnalysisHeavyIon.o
g++ -O3 -Wall -fPIC -pthread -std=c++11 -m64 -I/home/andsilva/build/include -I/home/andsilva/pythia8230/include -I/home/andsilva/pythia8230/examples/  -O3  -m64 -Wl,-rpath,/home/andsilva/pythia8230/lib/ -Wl,-rpath,/home/andsilva/pythia8230/examples/ doMyAnalysisHeavyIon.o -L/home/andsilva/build/lib -lGui -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTDataFrame -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -pthread -lm -ldl -rdynamic -L/home/andsilva/build/lib -lEve -lEG -lGeom -lGed -lRGL -lEG -lGui -lASImage -lASImageGui -L/home/andsilva/pythia8230/examples/ -lHxSimParticle -lHxSimEvent -o doMyAnalysisHeavyIon
/usr/bin/ld: cannot find -lHxSimParticle
/usr/bin/ld: cannot find -lHxSimEvent
collect2: error: ld returned 1 exit status
Makefile:33: recipe for target 'doMyAnalysisHeavyIon' failed
make: *** [doMyAnalysisHeavyIon] Error 1

 31 # compile/link doMyAnalysisHeavyIon 
 32 doMyAnalysisHeavyIon: doMyAnalysisHeavyIon.o
 33         $(CXX) $(CXXFLAGS)  $(LDFLAGS) $^ $(ROOTLIBS) $(HXLIBS) -o $@
 34 
 35 doMyAnalysisHeavyIon.o: doMyAnalysisHeavyIon.C
 36         $(CXX) $(CXXFLAGS) -c $^ -o $@

Folder with files .h and .cxx:

~/pythia8230/examples$ ls
HxSimParticle.cxx HxSimEvent.cxx HxSimParticle.h HxSimEvent.h HxSimParticleLinkDef.h HxSimEventLinkDef.h

Someone know how to fix this?
Cheers, Andre


#2

It’s not finding libHxSimParticle and libHxSimEvent…

What do you have in /home/andsilva/pythia8230/examples?


#3

Thanks for the reply!

$~/pythia8230/examples$ ls
Analysis                                HxSimParticle_cxx.d     main111LinkDef.h      main113LinkDef.h
HxSimEvent.cxx                          HxSimParticle_cxx.so    main111.so            main92.cc
HxSimEvent_cxx_ACLiC_dict_rdict.pcm     HxSimParticle.h         main112.cc            main92Dct_rdict.pcm
HxSimEvent_cxx.d                        HxSimParticleLinkDef.h  main112Dct_rdict.pcm  main92.h
HxSimEvent_cxx.so                       main111                 main112.h             main92LinkDef.h
HxSimEvent.h                            main111.cc              main112LinkDef.h      Makefile
HxSimEventLinkDef.h                     main111Dct.cc           main113.cc            Makefile.inc
HxSimParticle.cxx                       main111Dct_rdict.pcm    main113Dct_rdict.pcm
HxSimParticle_cxx_ACLiC_dict_rdict.pcm  main111.h               main113.h

#4

Well, try to execute:

cp -a $(HXPATH)/HxSimParticle_cxx.so $(HXPATH)/libHxSimParticle.so
cp -a $(HXPATH)/HxSimEvent_cxx.so $(HXPATH)/libHxSimEvent.so

or try with:

HXLIBS    = $(HXPATH)/HxSimParticle_cxx.so $(HXPATH)/HxSimEvent_cxx.so


#5

I try this

$ make doMyAnalysisHeavyIon
g++ -O3 -Wall -fPIC -pthread -std=c++11 -m64 -I/home/andsilva/build/include -I/home/andsilva/pythia8230/include -I/home/andsilva/pythia8230/examples/  -O3  -m64 -Wl,-rpath,/home/andsilva/pythia8230/lib/ -Wl,-rpath,/home/andsilva/pythia8230/examples/ doMyAnalysisHeavyIon.o -L/home/andsilva/build/lib -lGui -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTDataFrame -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -pthread -lm -ldl -rdynamic -L/home/andsilva/build/lib -lEve -lEG -lGeom -lGed -lRGL -lEG -lGui -lASImage -lASImageGui /home/andsilva/pythia8230/examples/HxSimParticle_cxx.so /home/andsilva/pythia8230/examples/HxSimEvent_cxx.so -o doMyAnalysisHeavyIon
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Makefile:38: recipe for target 'doMyAnalysisHeavyIon' failed
make: *** [doMyAnalysisHeavyIon] Error 1

Makefile:

 31 #HXLIBS    = -L$(HXPATH)/ -lHxSimParticle -lHxSimEvent
 32 HXLIBS    = $(HXPATH)/HxSimParticle_cxx.so $(HXPATH)/HxSimEvent_cxx.so
 33 
 34 # compile/link doMyAnalysisHeavyIon 
 35 doMyAnalysisHeavyIon: doMyAnalysisHeavyIon.o
 36         $(CXX) $(CXXFLAGS)  $(LDFLAGS) $^ $(ROOTLIBS) $(HXLIBS) -o $@
 37 
 38 doMyAnalysisHeavyIon.o: doMyAnalysisHeavyIon.C
 39         $(CXX) $(CXXFLAGS) -c $^ -o $@
 40 
 41 .PHONY: clean distclean
 42 
 43 # remove object files
 44 clean:
 45         @rm -f *.o
 46 
 47 # remove objects, libraries and dicts
 48 distclean: clean
 49         @rm -f $(PROGRAMS)

@Wile_E_Coyote Do you know how to fix this error?


#6

Well, “undefined reference to `main’” means that you did not provide the required C/C++ program entry point.


#7

Thanks for the answer @Wile_E_Coyote,

I still don’t get how to fix this, :confused:

$ ls
doMyAnalysisHeavyIon.C               HxSimEventDict.cxx        HxSimParticle.cxx                       HxSimParticleDict_rdict.pcm  pythia_heavy_ion_pPb.root
doMyAnalysisHeavyIon.o               HxSimEventDict.o          HxSimParticle_cxx_ACLiC_dict_rdict.pcm  HxSimParticle.h              pythia_heavy_ion_pp.root
HxSimEvent.cxx                       HxSimEventDict_rdict.pcm  HxSimParticle_cxx.d                     HxSimParticleLinkDef.h       pythia_HI.png
HxSimEvent_cxx_ACLiC_dict_rdict.pcm  HxSimEvent.h              HxSimParticle_cxx.so                    HxSimParticle.o
HxSimEvent_cxx.d                     HxSimEventLinkDef.h       HxSimParticleDict.cxx                   Makefile
HxSimEvent_cxx.so                    HxSimEvent.o              HxSimParticleDict.o                     pythia_heavy_ion_PbPb.root

Makefile:

all: libs programs

libs: HxSimParticle_cxx.so libHxSimEvent_cxx.so

programs  = doMyAnalysisHeavyIon

#LHAPDF    = LHAPDF-6.1.6
PYTHIA8   = /home/andre/pythia8235
HXPATH    = /home/andre/pythia8235/examples/Analysis

# define compiler/linker flags
CXX       = g++

CXXFLAGS  = -O3 -Wall -fPIC
CXXFLAGS += $(shell root-config --cflags)

LDFLAGS   = -O3 -Wl,-rpath,'$(HXPATH)'
LDFLAGS  += $(shell root-config --ldflags)

SOFLAGS   = -shared

ROOTLIBS  = $(shell root-config --libs --glibs --evelibs)

PROGRAMS = doMyAnalysisHeavyIon

# compile/link HxSimEvent
HxSimEvent_cxx.so: HxSimEventDict.o HxSimEvent.o HxSimParticleDict.o HxSimParticle.o
	$(CXX) $(SOFLAGS) $(LDFLAGS) $^ $(ROOTLIBS) -o $@ 

HxSimEvent.o: HxSimEvent.cxx
	$(CXX) $(CXXFLAGS) -c $^ -o $@ 

HxSimEventDict.o: HxSimEventDict.cxx
	$(CXX) $(CXXFLAGS) -c $^ -o $@ 

HxSimEventDict.cxx: HxSimEvent.h HxSimEventLinkDef.h
	rootcint -f $@ -c $(CXXFLAGS) -p $^

# compile/link HxSimParticle
HxSimParticle_cxx.so: HxSimParticleDict.o HxSimParticle.o
	$(CXX) $(SOFLAGS) $(LDFLAGS) $^ $(ROOTLIBS) -o $@ 

HxSimParticle.o: HxSimParticle.cxx
	$(CXX) $(CXXFLAGS) -c $^ -o $@ 

HxSimParticleDict.o: HxSimParticleDict.cxx
	$(CXX) $(CXXFLAGS) -c $^ -o $@ 

HxSimParticleDict.cxx: HxSimParticle.h HxSimParticleLinkDef.h
	rootcint -f $@ -c $(CXXFLAGS) -p $^

# compile/link doMyAnalysisHeavyIon 
doMyAnalysisHeavyIon: doMyAnalysisHeavyIon.o HxSimEvent_cxx.so HxSimParticle_cxx.so
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ $(ROOTLIBS) -o @

doMyAnalysisHeavyIon.o: doMyAnalysisHeavyIon.C
	$(CXX) $(CXXFLAGS) -c $^ -o $@

.PHONY: clean distclean

# remove object files
clean:
	@rm -f *.o

# remove objects, libraries and dicts
distclean: clean
	@rm -f *.so *Dict.* $(PROGRAMS)

My problem is in this part:

# compile/link doMyAnalysisHeavyIon 
doMyAnalysisHeavyIon: doMyAnalysisHeavyIon.o HxSimEvent_cxx.so HxSimParticle_cxx.so
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ $(ROOTLIBS) -o # Here

#8

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.