Build errors

Hi,

I am trying to compile simple class according to instructions in ch15 and I am getting the following errors:
[hits@rutpc1 ~/diamond]$ gmake -f Makefile
gcc -O2 -m32 Pixel_Info.o -o Pixel_Info
/usr/lib/gcc/i386-redhat-linux/3.4.6/…/…/…/crt1.o(.text+0x18): In function _start': : undefined reference tomain’
Pixel_Info.o(.text+0x4b): In function __tcf_0': : undefined reference tostd::ios_base::Init::~Init()'
Pixel_Info.o(.text+0x6f): In function global constructors keyed to _ZNK10Pixel_Info5PrintEv': : undefined reference tostd::ios_base::Init::Init()'
Pixel_Info.o(.text+0x99): In function global constructors keyed to _ZNK10Pixel_Info5PrintEv': : undefined reference toTVersionCheck::TVersionCheck(int)'
Pixel_Info.o(.text+0xac): In function global constructors keyed to _ZNK10Pixel_Info5PrintEv': : undefined reference toROOT::GenerateInitInstance(Pixel_Info const*)'
Pixel_Info.o(.text+0xb4): In function global constructors keyed to _ZNK10Pixel_Info5PrintEv': : undefined reference toROOT::TGenericClassInfo::SetImplFile(char const*, int)'
Pixel_Info.o(.gnu.linkonce.d.DW.ref.__gxx_personality_v0+0x0): undefined reference to `__gxx_personality_v0’
collect2: ld returned 1 exit status
gmake: *** [Pixel_Info] Error 1

here are .h file:

[code]#ifndef ROOT_Pixel_Info
#define ROOT_Pixel_Info

//////////////////////////////////////////////////////////////////////////
// //
// Pixel //
// //
// Description of the pixel info parameters //
// //
//////////////////////////////////////////////////////////////////////////

#include “TObject.h”
#include “TClonesArray.h”
#include “TRefArray.h”
#include “TRef.h”
#include “TH1.h”
#include “TBits.h”
#include “TMath.h”

//structure to hold pixel info
class Pixel_Info : public TObject {
private:
int row;
int column;
int n_range;
int range[2];
int n_vcal;
int n_tests;
int vcal[2][400];
float ADC[2][400][60];
public:
Pixel_Info() { row = 0; column = 0; n_range = 0; n_vcal=0; n_tests=0; }
virtual ~Pixel_Info() {}

 void Print() const;

 //getter
 int get_row() {return row;}
 int get_column() {return column;}
 int get_n_range() {return n_range;}
 int get_range(int i) {return range[i];}
 int get_n_vcal() {return n_vcal;}
 int get_n_tests() {return n_tests;}
 int get_vcal(int i, int j) {return vcal[i][j];}
 float get_ADC(int i, int j, int k) {return ADC[i][j][k];}
 //setters
 void set_row(int i) {row = i;}
 void set_column(int i) {column = i;}
 void set_n_range(int i) {n_range = i;}
 void set_range(int i, int j) {range[i] = j;}
 void set_n_vcal(int i) {n_vcal = i;}
 void set_n_tests(int i) {n_tests = i;}
 void set_vcal(int i, int j, int x) {vcal[i][j] = x;}
 void set_ADC(int i, int j, int k, float x) {ADC[i][j][k] = x;}
 ClassDef(Pixel_Info,1);

};
#endif
[/code]

And here the even smaller .cxx

[code]#include

#include “TMath.h”
#include “Pixel_Info.h”

ClassImp(Pixel_Info)

void Pixel_Info::Print() const {
printf(“row %d column %d”, row, column );
//cout << “row” << row << " column" << column << " vcal " << vcal[n_range][n_vcal] <<endl;
}[/code]

The Makefile I have made is simply cut and paste version of the original Fons Rademakers Makefile:

[code]#------------------------------------------------------------------------------

include Makefile.arch
-include …/MyConfig.mk

#------------------------------------------------------------------------------

PIXELO = Pixel_Info.$(ObjSuf) Pixel_InfoDict.$(ObjSuf)
PIXELS = Pixel_Info.$(SrcSuf) Pixel_InfoDict.$(SrcSuf)
PIXELSO = libPixel.$(DllSuf)
PIXEL = Pixel_Info$(ExeSuf)
ifeq ($(PLATFORM),win32)
PIXELLIB = libPixel_Info.lib
else
PIXELLIB = $(shell pwd)/$(PIXELSO)
endif

OBJS = $(PIXELO)

PROGRAMS = $(PIXEL)
#------------------------------------------------------------------------
.SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf)

all: $(PROGRAMS)

$(PIXELSO): $(PIXELO)

ifeq ($(ARCH),aix)
/usr/ibmcxx/bin/makeC++SharedLib $(OutPutOpt) $@ $(LIBS) -p 0 $^
else
ifeq ($(ARCH),aix5)
/usr/vacpp/bin/makeC++SharedLib $(OutPutOpt) $@ $(LIBS) -p 0 $^
else
ifeq ($(PLATFORM),macosx)

We need to make both the .dylib and the .so

	$(LD) $(SOFLAGS) $^ $(OutPutOpt) $@

ifneq ($(subst $(MACOSX_MINOR),1234),1234)
ifeq ($(MACOSX_MINOR),4)
ln -sf $@ $(subst .$(DllSuf),.so,$@)
else
$(LD) -bundle -undefined $(UNDEFOPT) $(LDFLAGS) $^
$(OutPutOpt) $(subst .$(DllSuf),.so,$@)
endif
endif
else
ifeq ($(PLATFORM),win32)
bindexplib $* $^ > $.def
lib -nologo -MACHINE:IX86 $^ -def:$
.def
$(OutPutOpt)$(EVENTLIB)
$(LD) $(SOFLAGS) $(LDFLAGS) $^ $*.exp $(LIBS)
$(OutPutOpt)$@
$(MT_DLL)
else
$(LD) $(SOFLAGS) $(LDFLAGS) $^ $(OutPutOpt) $@ $(EXPLLINKLIBS)
endif
endif
endif
endif
@echo “$@ done”

clean:
@rm -f $(OBJS) $(TRACKMATHSRC) core

distclean: clean
-@mv -f linearIO.root linearIO.roott
@rm -f $(PROGRAMS) $(EVENTSO) $(EVENTLIB) Dict. *.def *.exp
*.root *.ps *.so *.lib *.dll *.d *.log .def so_locations
@rm -rf cxx_repository files
-@mv -f linearIO.roott linearIO.root
-@cd RootShower && $(MAKE) distclean
-@cd rhtml && $(MAKE) distclean
-@cd RootIDE && $(MAKE) distclean

.SUFFIXES: .$(SrcSuf)

stressIterators.$(ObjSuf): stressIterators.h

Pixel_Info.$(ObjSuf): Pixel_Info.h

Pixel_InfoDict.$(SrcSuf): Pixel_Info.h Pixel_InfoLinkDef.h
@echo “Generating dictionary $@…”
$(ROOTCINT) -f $@ -c $^

.$(SrcSuf).$(ObjSuf):
$(CXX) $(CXXFLAGS) -c $<
[/code]

Please let me know if I am forgetting anything.

Thank you very much,

Dmitry.

Hi,

use g++ for LD, not gcc.

Axel.

Hi Axel,

Thank you for your reply. However, I have further questions. According to

root-config --arch

my arch is linux.

and in Makefile.arch LD is set to g++ for linux. Do you know why it did not happened?

I do include the Makefile.arch in the beginning of my Makefile.

Thank you again,

Dmitry.

Hi,

in the Makefile you miss the applications linking target like:

$(HWORLD):      $(HWORLDO)
                $(LD) $(LDFLAGS) $^ $(LIBS) $(OutPutOpt)$@
                $(MT_EXE)
                @echo "$@ done"

Thank you!

This got me to the next error:

[hits@rutpc1 ~/diamond]$ gmake -f Makefile
g++ -O2 -Wall -fPIC -pthread -m32 -I/usr/local/include/root -c Pixel_Info.cxx
g++ -O2 -m32 Pixel_Info.o Pixel_InfoDict.o -L/usr/local/lib/root -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -o Pixel_Info
/usr/lib/gcc/i386-redhat-linux/3.4.6/…/…/…/crt1.o(.text+0x18): In function _start': : undefined reference tomain’
collect2: ld returned 1 exit status
gmake: *** [Pixel_Info] Error 1

is there still something missing?

Dmitry.

Hi,

because you should build a library, passing $(SOFLAGS).

Why don’t you simply use ACLiC by running
root [0] .L Pixel_Info.cxx+
This is so much simpler than writing your own Makefile. In the end it does exactly what you do in your Makefile: call g++, rootcint, etc. And it even works on all platforms!

Cheers, Axel.

You need to provide a main program. Have a look at the examples in the test directory.

Cheers, Fons.

Thank you. The ACLiC works and indeed easy.

Dmitry.