Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Why is this "unresolved?"

Credits go to X-G for helping out!
This thread is locked; no one can reply to it. rss feed Print
Why is this "unresolved?"
GameCreator
Member #2,541
July 2002
avatar

From graphics.cpp

1#include "allegro.h"
2#include "graphics.h"
3 
4graphicssystem gfx;
5 
6// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7void graphicssystem::loadcharacter(int whichcharacter)
8{
9 switch(whichcharacter)
10 {
11 case UNDEAD2:
12 // Load standing "animation"
13 undead[0].sprite = load_bitmap("graphics\\32x64.bmp",undead[0].palette);
14 undead[0].width = 32;
15 undead[0].height = 64;
16 undead[0].totalframes = 1;
17 break;
18 default:
19 allegro_message("ERROR\n\nIt seems we're trying to load a character which doesn't exist!\n\nOh dear.");
20 break;
21 }
22}
23 
24...

From graphics.h

1...
2 
3struct charactersprite
4{
5 BITMAP *sprite;
6 PALETTE palette;
7 
8 int width;
9 int height;
10 int totalframes;
11};
12 
13extern struct charactersprite undead[15];
14 
15...

The above generates the following error from Visual Studio
graphics.obj : error LNK2019: unresolved external symbol "struct charactersprite * undead" (?undead@@3PAUcharactersprite@@A) referenced in function "public: void __thiscall graphicssystem::loadcharacter(int)" (?loadcharacter@graphicssystem@@QAEXH@Z) undead.exe : fatal error LNK1120: 1 unresolved externals

I've also attached the entire graphics.cpp and graphics.h files as they stand right now, should anyone want to see more.

Can anyone please let me know why that error comes up? It seems very mysterious to me, as the .h file is included and the thing is global.

Oh, and I looked up the Microsoft help for that error. It says this code should generate that error as well, but I don't know why either.

// LNK2019.cpp
// LNK2019 expected
extern char B[100];   // B is not in avilable to the linker
int main() {
   B[0] = ' ';
}

(Yes, that misspelling was part of it.) Why would B not be available to the linker? It's right there. I know, that's simplistic reasoning but at this point I just don't understand this. I've tried removing extern, I've tried moving the declaration to the .cpp file. All with no luck.

Thanks for any help.

Edit: Thanks X-G. File now uploaded.

X-G
Member #856
December 2000
avatar

Quote:

I've also attached the entire graphics.cpp and graphics.h

No you haven't. Besides, your problem is that you haven't defined undead for real anywhere, just an extern declaration.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

GameCreator
Member #2,541
July 2002
avatar

Got it. Added
struct charactersprite undead[15];
to graphics.cpp

Thanks!

Go to: