[SDL] OT - Undefined references in my project

Johannes Bauer dfnsonfsduifb at gmx.de
Sat Dec 1 06:42:57 PST 2007


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.

Greetings,
Johannes


More information about the SDL mailing list