[SDL] OT - Undefined references in my project

Michael Sullivan michael at espersunited.com
Sat Dec 1 06:47:31 PST 2007


On Sat, 2007-12-01 at 15:42 +0100, Johannes Bauer wrote:
> Michael Sullivan schrieb:
> 
> > all: battle.o character.o
> > 	reset; $(CC) $(CFLAGS) battle.o character.o $(LIBS) -o battle; rm *~
> 
> That should read
> 
> battle: battle.o character.o
> 
> Although it doesn't have anyting to do with your problem. Also include
> as the first two lines
> 
> .PHONY: all
> all: battle
> 
> > battle.cpp:(.text+0x9e3): undefined reference to
> > `Character::Character()'
> > battle.cpp:(.text+0xb35): undefined reference to
> > `Character::~Character()'
> [...]
> > I don't understand why.  This is my first SDL project, and my first
> > multifile C/C++ project, so I'm kinda out of my element here.  Thank you
> > in advance for your help...
> 
> Do you call the constructor anywhere, i.e. do you have a declaration
> like any of the following
> 
> Character c();
> Character c = Character();
> Character *c = new Character();
> 
> Maybe you use a class which relies on the empty constructor and
> assignment-operator, like std::map?
> 
> Character c('a');
> std::map<int, Character> mymap;
> mymap[7] = c;
> 
> Note that the above example invokes the Character() constructor as
> internally the "new" variant is called.
> 
> Simply create an empty () constructor and destructor and you'll likely
> be fine.
> 
michael at camille ourrpg $ grep 'Character()' character.h
      Character(); 
      virtual ~Character();

> Greetings,
> Johannes

Also, my Makefile has changed.  

CXX=g++
CFLAGS=-W -Wall -pedantic
LIBS=`sdl-config --cflags --libs` -lSDL_image -lSDL_gfx -lSDL_ttf
INC = -I/usr/include/SDL

all: battle

battle: battle.o character.o 
        $(CXX) -o $@ battle.o character.o $(LIBS)

%.o : %.cpp 
        $(CXX) $(CFLAGS) -c $< -o $@ $(INC)





More information about the SDL mailing list