Makefile errors: undefined reference(g++4.8.1,Ubuntu 12.04)

Recently, I am trying to do a GUI executable file using root. As a beginner, I am not familiar to makefile and this is my first time to compile a executable using makefile.
when I try to make , I got errors as following:

[quote]MyMainFrame.o: In function MyMainFrame::IsA() const': MyMainFrame.C:(.text._ZNK11MyMainFrame3IsAEv[_ZNK11MyMainFrame3IsAEv]+0x10): undefined reference toMyMainFrame::Class()’
MyMainFrame.o:([_ZTV11MyMainFrame]+0xe8): undefined reference to MyMainFrame::ShowMembers(TMemberInspector&)' MyMainFrame.o:([_ZTV11MyMainFrame]+0xec): undefined reference toMyMainFrame::Streamer(TBuffer&)’
MyMainFrame.o:([_ZTV11MyMainFrame]+0x2fc): undefined reference to non-virtual thunk to MyMainFrame::ShowMembers(TMemberInspector&)' MyMainFrame.o:([_ZTV11MyMainFrame]+0x300): undefined reference tonon-virtual thunk to MyMainFrame::Streamer(TBuffer&)’
collect2: error: ld returned 1 exit status
makefile:21: recipe for target ‘runGUI’ failed
make: *** [runGUI] Error 1

attached : Makefile below, and my code in attachments.
Someone please help.
thanks a lot!

ROOTCFLAGS    = $(shell root-config --cflags)
ROOTLIBS      = $(shell root-config --libs)
ROOTGLIBS     = $(shell root-config --glibs)

# Linux
CXX           = g++
CXXFLAGS      = -O -Wall -fPIC -I$(ROOTSYS)/include
LIBS          = $(ROOTLIBS) -lgcc -lm -ldl -rdynamic
GLIBS         = $(ROOTLIBS) $(ROOTGLIBS)                 

OBJS = MyMainFrame.o main.o

runGUI: ${OBJS}
	${CXX} -o runGUI ${CXXFLAGS} ${OBJS} $(LIBS) $(GLIBS)

MyMainFrame.o: MyMainFrame.C MyMainFrame.h
	${CXX} ${CXXFLAGS} -c MyMainFrame.C

main.o: main.C
	${CXX} ${CXXFLAGS} -c main.C

	rm -f runGUI ${OBJS}
	@echo "all cleaned up!"

MyMainFrame.h (654 Bytes)
MyMainFrame.C (2.37 KB)
main.C (358 Bytes)


You have to create the dictionary for your MyMainFrame class. Please take a look at the attached tar file, it contains everything needed to properly build your application. And BTW, when building standalone GUI application, you must create a TApplication and call TApplication::Run() in order to process events (take a look at the main.cxx file)

Cheers, Bertrand.
huoshi.tar.gz (1.97 KB)

That example was useful to me, thank you… :smiley:

thank bellenot for your great help!