| | |
" multiple definition of `game' ", " first defined here ", " ld returned 1 exit
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2009
Posts: 22
Reputation:
Solved Threads: 0
Hello everyone!
The title is actually most of my compiler output!
This is my entire compiler output:
And now this is all of my classes (The final function is that you'll be able to move around a sprite)..
Defs.h:
Draw.cpp:
Draw.h:
Graphics.cpp:
Graphics.h:
Init.cpp:
Init.h:
Input.cpp:
Input.h:
Main.cpp:
Main.h:
Player.cpp:
Player.h:
and finally
Structs.h:
That's all of my code.. And I use Dev C++ 4.9.9.2 as a compiler..
Please help me!
The title is actually most of my compiler output!
This is my entire compiler output:
C++ Syntax (Toggle Plain Text)
multiple definition of `game' first defined here ld returned 1 exit status C:\Documents and Settings\Benjamin Dahse\Skrivebord\SDL 2D Platform Game\Makefile.win [Build Error] ["2D] Error 1
And now this is all of my classes (The final function is that you'll be able to move around a sprite)..
Defs.h:
C++ Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "SDL/SDL.h" #include "SDL/SDL_image.h" #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 450 enum { PLAYER_SPRITE, MAX_SPRITES };
Draw.cpp:
C++ Syntax (Toggle Plain Text)
#include "Draw.h" extern void draw_player(void); extern void draw_entities(void); void draw() { SDL_FillRect(game.screen, NULL, 0); draw_player(); SDL_Flip(game.screen); SDL_Delay(1); } void delay(unsigned int frame_limit) { unsigned int ticks = SDL_GetTicks(); if(frame_limit < ticks) { return; } if(frame_limit > ticks + 16) { SDL_Delay(16); } else { SDL_Delay(frame_limit - ticks); } }
Draw.h:
C++ Syntax (Toggle Plain Text)
#include "Structs.h" Game game;
Graphics.cpp:
C++ Syntax (Toggle Plain Text)
#include "Graphics.h" SDL_Surface * load_image(char * name) { SDL_Surface * temp = IMG_Load(name); SDL_Surface * image = NULL; if(temp == NULL) { printf("Failed to load image %s\n", name); return NULL; } SDL_SetColorKey(temp, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(temp->format, 0, 0xFF, 0xFF)); image = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); if(image == NULL) { printf("Failed to convert image %s to native format\n", name); return NULL; } return image; } void draw_image(SDL_Surface * image, int x, int y) { SDL_Rect dest; dest.x = x; dest.y = y; dest.w = image->w; dest.h = image->h; SDL_BlitSurface(image, NULL, game.screen, & dest); } void load_sprite(int index, char *name) { if(index >= MAX_SPRITES || index < 0) { printf("Invalid index for sprite! Index: %d Maximum: %d\n", index, MAX_SPRITES); exit(1); } sprite[index].image = load_image(name); if (sprite[index].image == NULL) { exit(1); } } SDL_Surface * get_sprite(int index) { if(index >= MAX_SPRITES || index < 0) { printf("Invalid index for sprite! Index: %d Maximum: %d\n", index, MAX_SPRITES); exit(1); } return sprite[index].image; } void free_sprites() { int i; for(i = 0; i < MAX_SPRITES; i++) { if(sprite[i].image != NULL) { SDL_FreeSurface(sprite[i].image); } } } void load_all_sprites() { load_sprite(PLAYER_SPRITE, "GFX/firefly.png"); }
Graphics.h:
C++ Syntax (Toggle Plain Text)
#include "Structs.h" extern Sprites sprite[MAX_SPRITES]; extern Game game;
Init.cpp:
C++ Syntax (Toggle Plain Text)
#include "Init.h" extern void free_sprites(); void init(char * title) { if(SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Could not initialize SDL: %s\n", SDL_GetError()); exit(1); } game.screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_HWPALETTE|SDL_DOUBLEBUF); if(game.screen == NULL) { printf("Couldn't set screen mode to %d x %d: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_GetError()); exit(1); } SDL_WM_SetCaption(title, NULL); } void clean_up() { free_sprites(); SDL_Quit(); }
Init.h:
C++ Syntax (Toggle Plain Text)
#include "Structs.h" extern Game game;
Input.cpp:
C++ Syntax (Toggle Plain Text)
#include "Input.h" void get_input() { SDL_Event event; while(SDL_PollEvent(& event)) { switch(event.type) { case SDL_QUIT: exit(0); break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_UP: input.up = 1; break; case SDLK_DOWN: input.down = 1; break; case SDLK_LEFT: input.left = 1; break; case SDLK_RIGHT: input.right = 1; break; case SDLK_ESCAPE: exit(0); break; default: break; } break; case SDL_KEYUP: switch(event.key.keysym.sym) { case SDLK_UP: input.up = 0; break; case SDLK_DOWN: input.down = 0; break; case SDLK_LEFT: input.left = 0; break; case SDLK_RIGHT: input.right = 0; break; default: break; } break; } } }
Input.h:
C++ Syntax (Toggle Plain Text)
#include "Structs.h" extern Control input;
Main.cpp:
C++ Syntax (Toggle Plain Text)
#include "Main.h" extern void init(char *); extern void clean_up(void); extern void get_input(void); extern void draw(void); extern void init_player(void); extern void do_player(void); extern void do_entities(void); extern void load_all_sprites(void); extern void delay(unsigned int); int main(int argc, char *argv[]) { unsigned int frame_limit = SDL_GetTicks() + 16; int go; init("2D Game"); atexit(clean_up); go = 1; load_all_sprites(); init_player(); while(go == 1) { get_input(); do_player(); draw(); delay(frame_limit); frame_limit = SDL_GetTicks() + 16; } exit(0); }
Main.h:
C++ Syntax (Toggle Plain Text)
#include "Structs.h" Game game; Control input; Entity player; Sprites sprite[MAX_SPRITES];
Player.cpp:
C++ Syntax (Toggle Plain Text)
#include "Player.h" extern int load_sprite(char *); extern void draw_image(SDL_Surface *, int, int); extern SDL_Surface * get_sprite(int); void init_player() { player.sprite = get_sprite(PLAYER_SPRITE); player.x = SCREEN_WIDTH / 2; player.y = SCREEN_HEIGHT / 2; } void do_player() { if(input.up == 1) { player.y -= 3; if(player.y < 0) { player.y = 0; } } if(input.down == 1) { player.y += 3; if(player.y + player.sprite->h >= SCREEN_HEIGHT) { player.y = SCREEN_HEIGHT - (player.sprite->h + 1); } } if(input.left == 1) { player.x -= 3; if(player.x < 0) { player.x = 0; } } if(input.right == 1) { player.x += 3; if(player.x + player.sprite->w >= SCREEN_WIDTH) { player.x = SCREEN_WIDTH - (player.sprite->w + 1); } } } void draw_player() { draw_image(player.sprite, player.x, player.y); }
Player.h:
C++ Syntax (Toggle Plain Text)
#include "Structs.h" extern Entity player; extern Control input; extern Sprites sprites[MAX_SPRITES];
and finally
Structs.h:
C++ Syntax (Toggle Plain Text)
#include "Defs.h" typedef struct Game { SDL_Surface * screen; }Game; typedef struct Sprites { SDL_Surface * image; }Sprites; typedef struct Entity { int x, y; SDL_Surface * sprite; }Entity; typedef struct Control { int up, down, left, right; }Control;
That's all of my code.. And I use Dev C++ 4.9.9.2 as a compiler..

Please help me!
Re: " multiple definition of `game' ", " first defined here ", " ld returned 1 exit
0
#2 Aug 16th, 2009
•
•
Join Date: Aug 2009
Posts: 22
Reputation:
Solved Threads: 0
Re: " multiple definition of `game' ", " first defined here ", " ld returned 1 exi
0
#3 Aug 16th, 2009
Re: " multiple definition of `game' ", " first defined here ", " ld returned 1 exit
0
#4 Aug 16th, 2009
![]() |
Similar Threads
- "X not defined"? (Python)
- Multiple definition error (C++)
- Multiple definition of fcn error (C)
- "already defined" error (C++)
- google "keyword" question (Search Engine Optimization)
Other Threads in the C++ Forum
- Previous Thread: Re: Division between two integers and float result
- Next Thread: c++ background program
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets







But otherwise thanks for your help