#172374 - jamaozero - Wed Feb 03, 2010 11:46 am
I've cut down my proj to isolate the 'multiple definition of' error I'm having. Strange thing is, this error results when the function definition in a .cpp file, but when I inline it in the .h, it disappears.
error text:
1>linking multiboot
1>xero.o: In function `xeroActor::Update()':
1>c:/multidef/multidef/source/game/actors/xero.cpp:4: multiple definition of `xeroActor::Update()'
1>xero.o:c:/multidef/multidef/source/game/actors/xero.cpp:4: first defined here
1>xero.o:(.rodata+0x0): multiple definition of `vtable for xeroActor'
1>xero.o:(.rodata+0x0): first defined here
1>collect2: ld returned 1 exit status
1>make[1]: *** [/c/multidef/multidef/multidef_mb.elf] Error 1
Here is a readout of my 8 files (avg 15 lines), the filepaths, and the source:
file hierarchy:
\source\
actor.h
actor.cpp
main.cpp
\source\game\
game_actors.h
game_main.h
game_main.cpp
\source\game\actors\
xero.h
xero.cpp
main.cpp
actor.h
actor.cpp
game_actors.h
game_main.h
game_main.cpp
xero.h
xero.cpp
error text:
1>linking multiboot
1>xero.o: In function `xeroActor::Update()':
1>c:/multidef/multidef/source/game/actors/xero.cpp:4: multiple definition of `xeroActor::Update()'
1>xero.o:c:/multidef/multidef/source/game/actors/xero.cpp:4: first defined here
1>xero.o:(.rodata+0x0): multiple definition of `vtable for xeroActor'
1>xero.o:(.rodata+0x0): first defined here
1>collect2: ld returned 1 exit status
1>make[1]: *** [/c/multidef/multidef/multidef_mb.elf] Error 1
Here is a readout of my 8 files (avg 15 lines), the filepaths, and the source:
file hierarchy:
\source\
actor.h
actor.cpp
main.cpp
\source\game\
game_actors.h
game_main.h
game_main.cpp
\source\game\actors\
xero.h
xero.cpp
main.cpp
Code: |
/* Include the game main */ #include "game/game_main.h" int main() { game_main(); } |
actor.h
Code: |
#ifndef ACTOR_H #define ACTOR_H #include <gba_types.h> #include <gba_sprites.h> #include <gba_input.h> class actorBase { protected: u8 id; u8 x, y; u8 bndw, bndh; u8 bndxOfst, bndyOfst; u8 state; u8 allowInput; bool changed; SpriteEntry* sprite; public://private: //actor(); ~actorBase(); public: actorBase(u8 aid); actorBase(u8 aid, u8 ax, u8 ay, u8 abndw, u8 abndh, u8 abndxOfst, u8 abndyOfst); virtual void Update() = 0; } ALIGN(4); #endif |
actor.cpp
Code: |
#include "actor.h" actorBase::actorBase(u8 aid) : id(aid), x(0), y(0), bndw(0), bndh(0), bndxOfst(0), bndyOfst(0) { } actorBase::actorBase(u8 aid, u8 ax, u8 ay, u8 abndw, u8 abndh, u8 abndxOfst, u8 abndyOfst) : id(aid), x(ax), y(ay), bndw(abndw), bndh(abndh), bndxOfst(abndxOfst), bndyOfst(abndyOfst) { } |
game_actors.h
Code: |
#ifndef GAME_ACTORS_H #define GAME_ACTORS_H #include "actors\xero.h" #endif |
game_main.h
Code: |
#ifndef GAME_MAIN_H #define GAME_MAIN_H #include "game_actors.h" // need to break this later int game_main(); #endif |
game_main.cpp
Code: |
#include "game_main.h" int game_main() { xeroActor xero(0);// = new xeroActor(0); while(1) { scanKeys(); // required by gba_input.h xero.Update();//HandleInput(); } return 0; } |
xero.h
Code: |
#ifndef XERO_H #define XERO_H #include "..\..\actor.h" class xeroActor : public actorBase { friend class actorBase; public: xeroActor(u8 aid) : actorBase(aid) { } public: void Update();//HandleInput(); }; #endif |
xero.cpp
Code: |
#include "xero.h" void xeroActor::Update() { } |