multiple definition of "_gs_map"
-
Also, hier sind sie:
// main.cpp #include <SDL.h> #include "imgloader.h" #include "SonicSprites.h" #include "GreenhillSprites.h" #include <string> // Bildschirmeinstellungen const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 16; // Surfaces SDL_Surface *screen = NULL; SDL_Event event; void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) { //Make a temporary rectangle to hold the offsets SDL_Rect offset; //Give the offsets to the rectangle offset.x = x; offset.y = y; //Blit the surface SDL_BlitSurface( source, NULL, destination, &offset ); } int main( int argc, char* args[] ) { //Initialize all SDL subsystems if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return 1; } //Set the window caption bool quit = false; SDL_WM_SetCaption( "Event test", NULL ); //Set up the screen screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE ); //If there was an error in setting up the screen if( screen == NULL ) { return 1; } //Set the window caption SDL_WM_SetCaption( "Hello World", NULL ); // Sprites laden & einfügen ss_loadSprites(); apply_surface(20, 20, ss_getSprite(1), screen); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } // Game Loop while(quit == false) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) { //Programm beenden quit = true; } } } //Free the surfaces SDL_FreeSurface( message ); SDL_FreeSurface( background ); //Quit SDL SDL_Quit(); //Return return 0; }//GreenhillSprites.h #ifndef GREENHILLSPRITES_H_INCLUDED #define GREENHILLSPRITES_H_INCLUDED #include <SDL.h> #include <string> SDL_Rect gs_map[7]; SDL_Surface* gs_sprites; void gs_loadSprites(); void gs_spriteMap(); SDL_Surface* gs_getSprite(int sprite); #endif // GREENHILLSPRITES_H_INCLUDED//GreenhillSprites.cpp #include "GreenhillSprites.h" void gs_loadSprites() { // Surfaces definieren gs_sprites = NULL; // evtl *gs_sprites = NULL??? // Sprites Laden SDL_Surface* loader = NULL; loader = SDL_LoadBMP("greenhillsprites.bmp"); gs_sprites = SDL_DisplayFormat(loader); SDL_FreeSurface(loader); //Colorkey setzen Uint32 colorkey = SDL_MapRGB( gs_sprites->format, 0xFF, 0xFF, 0xFF ); SDL_SetColorKey( gs_sprites, SDL_SRCCOLORKEY, colorkey ); } SDL_Surface* gs_getSprite(int sprite) { SDL_Rect offset; offset.x = 0; offset.y = 0; SDL_Surface* destination; SDL_BlitSurface(gs_sprites, &gs_map[sprite], destination, &offset); return destination; } void gs_spriteMap() { gs_map[0].x = 1; gs_map[0].y = 1; gs_map[0].w = 255; gs_map[0].h = 255; gs_map[1].x = 258; gs_map[1].y = 1; gs_map[1].w = 255; gs_map[1].h = 255; gs_map[2].x = 515; gs_map[2].y = 1; gs_map[2].w = 255; gs_map[2].h = 255; gs_map[3].x = 1; gs_map[3].y = 3318; gs_map[3].w = 255; gs_map[3].h = 255; gs_map[4].x = 258; gs_map[4].y = 3318; gs_map[4].w = 255; gs_map[4].h = 255; gs_map[5].x = 515; gs_map[5].y = 3318; gs_map[5].w = 255; gs_map[5].h = 255; gs_map[6].x = 515; gs_map[6].y = 3543; gs_map[6].w = 255; gs_map[6].h = 255; }SonicSprites.h und SonicSprites.cpp sind identinsch mit Ausnahme der Methoden- und Variablennamen.
-
Du hast also diesen Teil 2 mal? (In 2 Headern):
SDL_Rect gs_map[7];Nach dieser Aussagen zu Folge:
SonicSprites.h und SonicSprites.cpp sind identinsch mit Ausnahme der Methoden- und Variablennamen.
-
Nein, die Variablennamen sind ja anders. Bei SonicSprites und der Headerdatei ist anstatt dem Kürzel gs überall das Kürzel ss vorne dran.
-
Dann tu mal alles nichtrelevante rauskommentieren bis es geht.
-
Bringt nix...
-
zilti schrieb:
Bringt nix...
Gibts nicht. Spätestens, wenn dein Projekt leer ist, sollte es gehen.
-
Ja, aber dann ist ja auch das Relevante raus.
-
Man definiert keine Variablen in Headerdateien.
Verschieb die Definition in eine Quellcodedatei, und schreib eine Deklaration in den Header (extern).
-
Wie geht denn ne Deklaration in der Headerdatei? (Bin ausm Java-Lager)
-
extern SDL_Rect gs_map[7];