English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm making a game in C++ but I get these errors that I don't know how to fix.

G:\SpaceCombat\SpaceCombatMain.o(.text$_ZN6ObjectC1Ev+0x5)
[Warning] In function `ZN10MenuObject9BeginPlayEv':

[Linker error] undefined reference to `Object::NumberOfObjects'

[Linker error] undefined reference to `Object::NumberOfObjects'

[Linker error] undefined reference to `Object::NumberOfObjects'

[Linker error] undefined reference to `Scene::SceneN'

[Linker error] undefined reference to `Scene::SceneN'

[Linker error] undefined reference to `Scene::SceneN'

The compile log shows


SpaceCombatMain.o(.text$_ZN6ObjectC1Ev+0x5): In function `ZN10MenuObject9BeginPlayEv':
G:/SpaceCombat/LevelFile.h: undefined reference to `Object::NumberOfObjects'
SpaceCombatMain.o(.text$_ZN6ObjectC1Ev+0xd):G:/SpaceCombat/LevelFile.h: undefined reference to `Object::NumberOfObjects'

SpaceCombatMain.o(.text$_ZN6ObjectD1Ev+0x5):G:/SpaceCombat/LevelFile.h: undefined reference to `Object::NumberOfObjects'
SpaceCombatMain.o(.text$_ZN5SceneC1Ev+0x5):G:/SpaceCombat/LevelFile.h: undefined reference to `Scene::SceneN'
SpaceCombatMain.o(.text$_ZN5SceneC1Ev+0xd):G:/SpaceCombat/LevelFile.h: undefined reference to `Scene::SceneN'
SpaceCombatMain.o(.text$_ZN5SceneD1Ev+0x5):G:/SpaceCombat/LevelFile.h: undefined reference to `Scene::SceneN'

2006-08-01 17:50:32 · 2 answers · asked by DukeInstinct 2 in Computers & Internet Programming & Design

Object::NoOfObjects is a static int
Scene::SceneN is also a static int

2006-08-01 18:17:40 · update #1

2 answers

It seems like the definitions of Scene and Object class is not being linked to your final executable. Check if you have compiled Object.obj and Scene.obj and if it is included in your final link.exe step.

2006-08-01 18:16:58 · answer #1 · answered by swami060 3 · 0 0

When linking two files, it sometimes helps to specify external linkage in the header and then declare the object in the definition file, ie.:

extern Object anObject;

Also, when directly referencing a function in the manner Object::NumberOfObjects, the function must be static.

Could you explain in more detail how you are referencing the integers and how your files are linked together.

2006-08-01 19:35:13 · answer #2 · answered by jacinablackbox 4 · 0 0

fedest.com, questions and answers