Undefined References
Michael Sullivan
michael@espersunited.com
Sat Dec 1 14:28:00 GMT 2007
On Sat, 2007-12-01 at 08:22 -0600, Tom Browder wrote:
> On Dec 1, 2007 7:27 AM, Michael Sullivan <michael@espersunited.com> wrote:
> > My Makefile is now:
> ...
> > %.o : %.cpp
> > $(CXX) $(CFLAGS) $< -c $@ $(INC)
>
> The '-c' is misplaced. The '$@' refers to the object file and the
> '$<' refers to the source file. So:
>
> %.o : %.cpp
> $(CXX) $(CFLAGS) -c $< -o $@ $(INC)
>
> -Tom
michael@camille ourrpg $ rm *.o
michael@camille ourrpg $ make
g++ -W -Wall -pedantic -c battle.cpp -o battle.o -I/usr/include/SDL
battle.cpp: In member function 'SDL_Surface* battle::drawString(int,
int, char*)':
battle.cpp:72: warning: missing initializer for member
'SDL_Color::unused'
g++ -W -Wall -pedantic -c character.cpp -o character.o
-I/usr/include/SDL
g++ -o battle battle.o character.o `sdl-config --cflags --libs`
-lSDL_image -lSDL_gfx -lSDL_ttf
battle.o: In function `battle::battle()':
battle.cpp:(.text+0x9e3): undefined reference to
`Character::Character()'
battle.cpp:(.text+0xb35): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xb83): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xbd1): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0xc16): undefined reference to
`Character::~Character()'
battle.o: In function `battle::battle()':
battle.cpp:(.text+0xf19): undefined reference to
`Character::Character()'
battle.cpp:(.text+0x106b): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x10b9): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x1107): undefined reference to
`Character::~Character()'
battle.cpp:(.text+0x114c): undefined reference to
`Character::~Character()'
character.o: In function `Character::Character(char*, long, long)':
character.cpp:(.text+0xdb): undefined reference to `vtable for
Character'
character.o: In function `Character::Character(char*, long, long)':
character.cpp:(.text+0x12d): undefined reference to `vtable for
Character'
collect2: ld returned 1 exit status
make: *** [battle] Error 1
michael@camille ourrpg $ cat Makefile
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 Gcc-help
mailing list