Sign in to follow this  
lukeymoo

Allegro Linker Error

Recommended Posts

[font=arial, verdana, tahoma, sans-serif][size=2]Hey everyone, I've tried searching around multiple forums and sites in search of an answer but none seem to work.
I have a header file that holds global BITMAP variables and I've included them in 2 CPP files, that is the gameEngine.cpp and Main.cpp[/size][/font][font=arial, verdana, tahoma, sans-serif][size=2]I've posted this before, but I guess I did so in the wrong forum as I got no replies.

Here is my Bitmaps.h file
[source lang='cpp']
#ifndef BITMAPS_H
#define BITMAPS_H
#include

extern BITMAP *buffer;
extern BITMAP *p_right;
extern BITMAP *p_left;
extern BITMAP *p_jump_left;
extern BITMAP *p_jump_right;[source='gameEngine.cpp']if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) < 0) { MessageBox(NULL, "Allegro failed to initialize the graphics!", "Error!", MB_OK | MB_ICONEXCLAMATION); exit(1); } set_window_title("TITLE REMOVED"); BITMAP *buffer = create_bitmap(640, 480); BITMAP *p_right = load_bitmap("gfx\\p_right.bmp", NULL); BITMAP *p_left = load_bitmap("gfx\\p_left.bmp", NULL); BITMAP *p_jump_left = load_bitmap("gfx\\p_jump_left.bmp", NULL); BITMAP *p_jump_right = load_bitmap("gfx\\p_jump_right.bmp", NULL); BITMAP *menu_background = load_bitmap("data\\menu_background.bmp", NULL); BITMAP *menu_play = load_bitmap("data\\play.bmp", NULL); BITMAP *menu_info = load_bitmap("data\\info.bmp", NULL); BITMAP *menu_exit = load_bitmap("data\\exit.bmp", NULL);[/source]

extern BITMAP *menu_background;
extern BITMAP *menu_play;
extern BITMAP *menu_info;
extern BITMAP *menu_exit;
#endif[/source]
[font="arial, verdana, tahoma, sans-serif"][size="2"]Sorry for long post,

And here is a snippet of my gameEngine.cpp in the 'init()' function
[source lang="cpp"]
set_window_title("Halo: The Untold");
BITMAP *buffer = create_bitmap(640, 480);
BITMAP *p_right = load_bitmap("gfx\\p_right.bmp", NULL);
BITMAP *p_left = load_bitmap("gfx\\p_left.bmp", NULL);
BITMAP *p_jump_left = load_bitmap("gfx\\p_jump_left.bmp", NULL);
BITMAP *p_jump_right = load_bitmap("gfx\\p_jump_right.bmp", NULL);
BITMAP *menu_background = load_bitmap("data\\menu_background.bmp", NULL);
BITMAP *menu_play = load_bitmap("data\\play.bmp", NULL);
BITMAP *menu_info = load_bitmap("data\\info.bmp", NULL);
BITMAP *menu_exit = load_bitmap("data\\exit.bmp", NULL);
show_mouse(screen);
[/source]
And my main.cpp's use of these BITMAPs
[source lang="cpp"]
switch(g.state)
{
case MENUSCREEN:
//making menuscreen background
draw_sprite(buffer, menu_background, 0, 0);
masked_blit(menu_play, buffer, 0, 0, 300, 300, 189, 50);
masked_blit(menu_info, buffer, 0, 0, 300, 350, 189, 50);
masked_blit(menu_exit, buffer, 0, 0, 300, 400, 189, 50);
/*play = 300, 300 info = 300, 350 exit = 300, 400*/
break;
case GAME:
break;
case CREDITS:
break;
}
[/source]
Here are the list of confusing linker errors
[code]<div>Linking...
gameEngine.obj : error LNK2001: unresolved external symbol "struct BITMAP * menu_exit" (?menu_exit@@3PAUBITMAP@@A)
Main.obj : error LNK2001: unresolved external symbol "struct BITMAP * menu_exit" (?menu_exit@@3PAUBITMAP@@A)
gameEngine.obj : error LNK2001: unresolved external symbol "struct BITMAP * menu_info" (?menu_info@@3PAUBITMAP@@A)
Main.obj : error LNK2001: unresolved external symbol "struct BITMAP * menu_info" (?menu_info@@3PAUBITMAP@@A)
gameEngine.obj : error LNK2001: unresolved external symbol "struct BITMAP * menu_play" (?menu_play@@3PAUBITMAP@@A)
Main.obj : error LNK2001: unresolved external symbol "struct BITMAP * menu_play" (?menu_play@@3PAUBITMAP@@A)
gameEngine.obj : error LNK2001: unresolved external symbol "struct BITMAP * menu_background" (?menu_background@@3PAUBITMAP@@A)
Main.obj : error LNK2001: unresolved external symbol "struct BITMAP * menu_background" (?menu_background@@3PAUBITMAP@@A)
gameEngine.obj : error LNK2001: unresolved external symbol "struct BITMAP * p_jump_right" (?p_jump_right@@3PAUBITMAP@@A)
gameEngine.obj : error LNK2001: unresolved external symbol "struct BITMAP * p_jump_left" (?p_jump_left@@3PAUBITMAP@@A)
gameEngine.obj : error LNK2001: unresolved external symbol "struct BITMAP * p_right" (?p_right@@3PAUBITMAP@@A)
gameEngine.obj : error LNK2001: unresolved external symbol "struct BITMAP * p_left" (?p_left@@3PAUBITMAP@@A)
gameEngine.obj : error LNK2001: unresolved external symbol "struct BITMAP * buffer" (?buffer@@3PAUBITMAP@@A)
Main.obj : error LNK2001: unresolved external symbol "struct BITMAP * buffer" (?buffer@@3PAUBITMAP@@A)
[/code]
Thanks ahead for reply :][/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
So take the first error, for example:

> gameEngine.obj : error LNK2001: unresolved external symbol "struct BITMAP * menu_exit" (?menu_exit@@3PAUBITMAP@@A)

You've used menu_exit in your code, but the linker can't actually resolve that to a variable. I.e., it can't find the definition. So...you have to ask yourself, where is the definition?

Share this post


Link to post
Share on other sites
Well the definition is in the gameEngine.cpp, which I don't think can be used can it ? But even if it couldn't I've also tried placing the definitions in different places such as in Main.cpp and Even in the Bitmaps.h and it'd throw the same errors at me..I've also tried using it without extern. I am just really really stumped right now.

Share this post


Link to post
Share on other sites
> Well the definition is in the gameEngine.cpp

At global scope? "And here is a snippet of my gameEngine.cpp in the 'init()' function" So all those definitions are at function scope, which doesn't correspond to the global declarations.

> But even if it couldn't I've also tried placing the definitions in different places such as in Main.cpp and Even in the Bitmaps.h

The definition goes in a cpp file. Not in a header file.

> .I've also tried using it without extern.

Turning your declaration in a header file into a definition. Not correct.

Share this post


Link to post
Share on other sites
I've taken your advice, and put the definitions in global scope of gameEngine.cpp and It compiles correctly but now it's giving me access violations on run-time for each of the Bitmaps, had this problem before, but this one seems to need a different solution.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this