[debutant]Multifichier/SDL, Declaration multiple
Salut à tous :)
Je voudrais commencer un petit projet en C/ogl/SDL, mais je bloque dès le début sur une erreur que je ne parviens pas à corriger.
Voilà mes sources:
main.c
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "header.h"
Ecran screen;
int main (int argc, char *argv[])
{
screen.hauteur=600;
screen.largeur=800;
screen.profondeur=32;
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)
{
fprintf(stderr, "An error has occured while loading the SDL lib: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
return 0;
}
if (SDL_SetVideoMode(screen.largeur, screen.hauteur, screen.profondeur, SDL_OPENGL)==NULL)
{
fprintf(stderr, "An error has occured while initializing the video/render mode: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
return 0;
}
SDL_WM_SetCaption("A testProgramm", NULL);
intro();
} |
evenements_clavier.c
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "header.h"
void UpdateEvents()
{
while(SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
key[event.key.keysym.sym]=1;
break;
case SDL_KEYUP:
key[event.key.keysym.sym]=0;
break;
case SDL_MOUSEMOTION:
xsouris=event.motion.x;
ysouris=event.motion.y;
xrelsouris=event.motion.xrel;
yrelsouris=event.motion.yrel;
break;
case SDL_MOUSEBUTTONDOWN:
boutons[event.button.button-1]=1;
break;
case SDL_MOUSEBUTTONUP:
boutons[event.button.button-1]=0;
break;
}
}
} |
header.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #ifndef DEF_HEADER
#define DEF_HEADER
#define TRUE 1
#define FALSE 0
SDL_Event event;
char key[400];
int xsouris=0,xrelsouris=0,yrelsouris=0,ysouris=0;
char boutons[3]={0,0,0};
typedef struct Ecran Ecran;
struct Ecran
{
int largeur;
int hauteur;
int profondeur;
};
void pause();
int intro();
void UpdateEvents();
#endif |
intro.c
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "header.h"
int intro()
{
int continuer=TRUE;
glClearColor(0.0, 0.0, 0.0, 0.0);
return 0;
} |
quit.c
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "header.h"
int quit()
{
SDL_Quit();
return 0;
} |
et l'erreur c'est :
multiple definition of `xsouris' first defined here (mais quand on clique ça ne va nulpart) de même pour xrelsouris, yrelsouris, ysouris=0 et boutons
Merci de m'expliquer, parce que là, je me demande vraiment si le compilo déconne pas (j'utilise devcpp sur windows)
edit: je viens de me rendre compte que je me suis planté de forum, désolé (si un modo passe par là et qu'il veuille bien le remettre dans C, ce serait sympa, merci :) )