IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Probleme definition multiple de variables


Sujet :

C++

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 8
    Points : 5
    Points
    5
    Par défaut Probleme definition multiple de variables
    Bonjour, je doit faire en devoir un jeu d'echec, et je m'emelle avec les headers... J'ai une erreur de definition multiple des variables ^^'
    Je code avec SDL, si pouviez m'aider ça serait cool
    Voici mon code :

    main :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
     
    #include <SDL/SDL.h>
    #include <SDL/SDL_image.h>
    #include <SDL/SDL_ttf.h>
    #include "constantes.h"
    #include <string>
    #include "fonctions.h"
    #include "global.h"
     
     
     
    int main( int argc, char* args[] )
    {
        int positiontx = 260;
        int positionty = 805-80;
        int positionBlancx = 300;
        int positionBlancy = 140;
        int positionVertx = 380;
        int positionVerty = 140;
     
     
        //Make sure the program waits for a quit
        bool quit = false;
     
        //Initialize
        if( init() == false )
        {
            return 1;
        }
     
        //Load the files
        if( load_files() == false )
        {
            return 1;
        }
     
        //Apply the surface to the screen
        apply_surface( 0, 0, imageDeFond, screen );
            char lettre[2]="A";
     
        for(char k='A'; k<'I'; k++)
        {
            lettre[0]=k;
            texte = TTF_RenderText_Blended(police,lettre,textColor);
            apply_surface( positiontx, positionty, texte, screen);
            positionty-=80;
        }
        positiontx = 260+640+60;
        positionty = 805-80;
     
        char lettre2[2]="A";
     
        for(char k='A'; k<'I'; k++)
        {
            lettre2[0]=k;
            texte = TTF_RenderText_Blended(police,lettre2,textColor);
            apply_surface( positiontx, positionty, texte, screen);
            positionty-=80;
        }
        positiontx = 330;
        positionty = 100;
     
        char chiffre[2]="1";
        for(char k='1'; k<'9'; k++)
        {
            chiffre[0]=k;
            texte = TTF_RenderText_Blended(police,chiffre,textColor);
            apply_surface( positiontx, positionty, texte, screen);
            positiontx+=80;
        }
        positiontx = 330;
        positionty = 790;
     
        char chiffre2[2]="1";
        for(char k='1'; k<'9'; k++)
        {
            chiffre2[0]=k;
            texte = TTF_RenderText_Blended(police,chiffre2,textColor);
            apply_surface( positiontx, positionty, texte, screen);
            positiontx+=80;
        }
     
     //If there was an error in rendering the text
        if( texte == NULL )
        {
            return 1;
        }
     
     
        do
        {
            do
            {
                apply_surface( positionBlancx, positionBlancy, blanc, screen );
                positionBlancx = positionBlancx+160;
     
                apply_surface( positionVertx, positionVerty, vert, screen );
                positionVertx = positionVertx+160;
     
            }while(positionBlancx < 890 && positionVertx < 975);
     
            positionBlancx = 300;
            positionBlancy = positionBlancy+160;
     
            positionVertx = 380;
            positionVerty =  positionVerty+160;
     
        }while (positionBlancy <  640+140 && positionVerty < 640+140);
     
        positionBlancx = 380;
        positionBlancy = 80+140;
        positionVertx = 300;
        positionVerty = 80+140;
     
        do
        {
            do
            {
               apply_surface( positionBlancx, positionBlancy, blanc, screen );
               positionBlancx = positionBlancx+160;
     
               apply_surface( positionVertx, positionVerty, vert, screen );
               positionVertx = positionVertx+160;
            }while(positionBlancx < 975 && positionVertx < 890);
     
            positionVertx = 300;
            positionVerty = positionVerty+160;
            positionBlancx = 380;
            positionBlancy = positionBlancy+160;
            }while (positionBlancy < 640+140 && positionVerty < 640+140);
     
     
        //Update the screen
        if( SDL_Flip( screen ) == -1 )
        {
            return 1;
        }
     
        //While the user hasn't quit
        //Tant que l'utilisateur n'a pas quitter
        while( quit == false )
        {
            //tant qu'il y a un evenement dans le handler
            while( SDL_PollEvent( &event ) )
            {
                //Si l'utilisateur ferme la fenetre avec le X
                if( event.type == SDL_QUIT )
                {
                    //On quitte le programme
                    quit = true;
                }
            }
        }
        clean_up();
        return 0;
    }

    fonction.cpp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
     
    #include "SDL/SDL.h"
    #include "SDL/SDL_image.h"
    #include <string>
    #include "constantes.h"
    #include "fonctions.h"
    #include "global.h"
     
    SDL_Surface *load_image( std::string filename )
    {
        //The image that's loaded
        SDL_Surface* loadedImage = NULL;
     
        //The optimized image that will be used
        SDL_Surface* optimizedImage = NULL;
     
        //Load the image
        loadedImage = IMG_Load( filename.c_str() );
     
        //If the image loaded
        if( loadedImage != NULL )
        {
            //Create an optimized image
            optimizedImage = SDL_DisplayFormat( loadedImage );
     
            //Free the old image
            SDL_FreeSurface( loadedImage );
     
            if( optimizedImage != NULL )
            {
                //Map the color key
                Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF );
                //Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
                SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );
            }
     
        }
     
        //Return the optimized image
        return optimizedImage;
    }
     
     
    void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
    {
     
        SDL_Rect offset;
     
        offset.x = x;
        offset.y = y;
     
        //on blit la surface
        SDL_BlitSurface( source, NULL, destination, &offset );
    }
     
    bool init()
    {
        //Initialize all SDL subsystems
        if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
        {
            return false;
        }
     
        //Set up the screen
        screen = SDL_SetVideoMode(1280, 960, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
     
        //If there was an error in setting up the screen
        if( screen == NULL )
        {
            return false;
        }
     
        //Initialize SDL_ttf
        if( TTF_Init() == -1 )
        {
            return false;
        }
     
        //Set the window caption
        SDL_WM_SetCaption( "Event test", NULL );
     
        //If everything initialized fine
        return true;
    }
     
     
    bool load_files()
    {
        //Load the image
        imageDeFond = load_image( "images/pierre.jpg" );
        vert = load_image("images/vert.jpg");
        blanc = load_image("images/blanc.jpg");
        pieceFouNoir = load_image("images/pieceFouNoir.bmp");
        pieceFouBlanc = load_image("images/pieceFouBlanc.bmp");
        pieceDameNoir = load_image("images/pieceDameNoir.bmp");
        pieceDameBlanc = load_image("images/pieceDameBlanc.bmp");
        pieceCavalierNoir = load_image("images/pieceCavalierNoir.bmp");
        pieceCavalierBlanc = load_image("images/pieceCavalierBlanc.bmp");
        pieceRoiNoir = load_image("images/pieceRoiNoir.bmp");
        pieceRoiBlanc = load_image("images/pieceRoiBlanc.bmp");
        pieceTourNoir = load_image("images/pieceTourNoir.bmp");
        pieceTourBlanc = load_image("images/pieceTourBlanc.bmp");
        piecePionNoir = load_image("images/piecePionNoir.bmp");
        piecePionBlanc = load_image("images/piecePionBlanc.bmp");
     
        police = TTF_OpenFont("calibri.ttf", 35);
     
        //If there was an error in loading the image
        if( imageDeFond == NULL )
        {
            return false;
        }
     
        //If there was an error in loading the font
        if( police == NULL )
        {
            return false;
        }
     
        //If everything loaded fine
        return true;
    }
     
     
    void clean_up()
    {
        //Free the image
        SDL_FreeSurface(pieceFouNoir);
        SDL_FreeSurface(pieceFouBlanc);
        SDL_FreeSurface(pieceDameNoir);
        SDL_FreeSurface(pieceDameBlanc);
        SDL_FreeSurface(pieceCavalierNoir);
        SDL_FreeSurface(pieceCavalierBlanc);
        SDL_FreeSurface(pieceRoiNoir);
        SDL_FreeSurface(pieceRoiBlanc);
        SDL_FreeSurface(pieceTourNoir);
        SDL_FreeSurface(pieceTourBlanc);
        SDL_FreeSurface(piecePionNoir);
        SDL_FreeSurface(piecePionBlanc);
        SDL_FreeSurface(imageDeFond);
        SDL_FreeSurface(vert);
        SDL_FreeSurface(blanc);
        //Quit SDL
        SDL_Quit();
    }
    .h :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #ifndef FoNCTIONS_H
    #define FoNCTIONS_H
     
    //The headers
    #include "SDL/SDL.h"
    #include "SDL/SDL_image.h"
    #include <string>
     
    //File Loader
    SDL_Surface *load_image( std::string filename );
     
    //Surface blitter
    void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination );
     
    //Initialization
    bool init();
     
    //File loading
    bool load_files();
     
    //Clean up
    void clean_up();
     
    #endif
    et les variable globales (je sais c'est pas bien ) :
    .cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    //The headers
    #include "SDL/SDL.h"
    #include "global.h"
     
    //The surfaces
    SDL_Surface *imageDeFond = NULL;
    SDL_Surface *vert = NULL;
    SDL_Surface *blanc;
    SDL_Surface *texte = NULL;
    SDL_Surface *screen = NULL;
    SDL_Surface *piecePionBlanc = NULL;
    SDL_Surface *piecePionNoir = NULL;
    SDL_Surface *pieceRoiNoir = NULL;
    SDL_Surface *pieceRoiBlanc = NULL;
    SDL_Surface *pieceTourBlanc = NULL;
    SDL_Surface *pieceTourNoir = NULL;
    SDL_Surface *pieceFouBlanc = NULL;
    SDL_Surface *pieceFouNoir = NULL;
    SDL_Surface *pieceCavalierNoir = NULL;
    SDL_Surface *pieceCavalierBlanc = NULL;
    SDL_Surface *pieceDameNoir = NULL;,
    SDL_Surface *pieceDameBlanc = NULL;
     
    //The event structure
    SDL_Event event;
    .h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    39
    #ifndef GLOBAL_H
    #define GLOBAL_H
     
    #include "SDL/SDL.h"
    #include "SDL/SDL_ttf.h"
     
    //extern struct Forme quadri[16][12];
     
    //Echiquier
    extern SDL_Surface *imageDeFond = NULL;
    extern SDL_Surface *vert = NULL;
    extern SDL_Surface *blanc;
    extern SDL_Surface *texte = NULL;
    extern SDL_Surface *screen = NULL;
     
     
    //Pieces
    extern SDL_Surface *piecePionBlanc = NULL;
    extern SDL_Surface *piecePionNoir = NULL;
    extern SDL_Surface *pieceRoiNoir = NULL;
    extern SDL_Surface *pieceRoiBlanc = NULL;
    extern SDL_Surface *pieceTourBlanc = NULL;
    extern SDL_Surface *pieceTourNoir = NULL;
    extern SDL_Surface *pieceFouNoir = NULL;
    extern SDL_Surface *pieceFouBlanc = NULL;
    extern SDL_Surface *pieceCavalierNoir = NULL;
    extern SDL_Surface *pieceCavalierBlanc = NULL;
    extern SDL_Surface *pieceDameNoir = NULL;
    extern SDL_Surface *pieceDameBlanc = NULL;
     
    //Texte
    extern TTF_Font *police = NULL;
    extern SDL_Color textColor = { 0, 0, 0 };
     
    //La structure d'evenement
    extern SDL_Event event;
     
     
    #endif // GLOBAL_H
    J'ai aussi un .h constantes mais il n'y a que la definition d'une structure que je ne n'utilise pas encore !

    Merci de votre aide !

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Network game programmer
    Inscrit en
    Juin 2010
    Messages
    7 115
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Canada

    Informations professionnelles :
    Activité : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 115
    Points : 32 967
    Points
    32 967
    Billets dans le blog
    4
    Par défaut
    Bonsoir,

    pourrait-on voir le vrai message d'erreur complet ?
    Il y a de forte chance qu'il indique où se situe le problème (ie: c'est carrément sur que sa simple lecture montre l'origine du souci).
    Probablement un pb d'includes.
    Pensez à consulter la FAQ ou les cours et tutoriels de la section C++.
    Un peu de programmation réseau ?
    Aucune aide via MP ne sera dispensée. Merci d'utiliser les forums prévus à cet effet.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 8
    Points : 5
    Points
    5
    Par défaut
    C'est sur que ça viens des includes ^^
    Voici le message !
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
     
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|10|warning: 'imageDeFond' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|11|warning: 'vert' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|13|warning: 'texte' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|14|warning: 'screen' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|18|warning: 'piecePionBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|19|warning: 'piecePionNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|20|warning: 'pieceRoiNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|21|warning: 'pieceRoiBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|22|warning: 'pieceTourBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|23|warning: 'pieceTourNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|24|warning: 'pieceFouNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|25|warning: 'pieceFouBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|26|warning: 'pieceCavalierNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|27|warning: 'pieceCavalierBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|28|warning: 'pieceDameNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|29|warning: 'pieceDameBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|32|warning: 'police' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|33|warning: 'textColor' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|10|warning: 'imageDeFond' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|11|warning: 'vert' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|13|warning: 'texte' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|14|warning: 'screen' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|18|warning: 'piecePionBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|19|warning: 'piecePionNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|20|warning: 'pieceRoiNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|21|warning: 'pieceRoiBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|22|warning: 'pieceTourBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|23|warning: 'pieceTourNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|24|warning: 'pieceFouNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|25|warning: 'pieceFouBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|26|warning: 'pieceCavalierNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|27|warning: 'pieceCavalierBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|28|warning: 'pieceDameNoir' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|29|warning: 'pieceDameBlanc' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|32|warning: 'police' initialized and declared 'extern' [enabled by default]|
    C:\Users\N-Sailly\Programmes\Projet\Chess\global.h|33|warning: 'textColor' initialized and declared 'extern' [enabled by default]|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `imageDeFond'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|9|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `vert'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|9|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `texte'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|11|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `screen'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|11|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `piecePionBlanc'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|14|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `piecePionNoir'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|17|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `pieceRoiNoir'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|17|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `pieceRoiBlanc'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|17|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `pieceTourBlanc'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|17|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `pieceTourNoir'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|17|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `pieceFouNoir'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|20|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `pieceFouBlanc'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|20|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `pieceCavalierNoir'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|23|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|12|multiple definition of `pieceCavalierBlanc'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|23|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|13|multiple definition of `pieceDameNoir'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|23|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|13|multiple definition of `pieceDameBlanc'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|26|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|14|multiple definition of `police'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|26|first defined here|
    obj\Debug\main.o||In function `SDL_main':|
    C:\Users\N-Sailly\Programmes\Projet\Chess\main.cpp|14|multiple definition of `textColor'|
    obj\Debug\fonctions.o:C:\Users\N-Sailly\Programmes\Projet\Chess\fonctions.cpp|26|first defined here|
    obj\Debug\fonctions.o:fonctions.cpp|| undefined reference to `blanc'|
    obj\Debug\fonctions.o:fonctions.cpp|| undefined reference to `blanc'|
    obj\Debug\main.o:main.cpp|| undefined reference to `blanc'|
    obj\Debug\main.o:main.cpp|| undefined reference to `blanc'|
    obj\Debug\main.o:main.cpp|| undefined reference to `event'|
    obj\Debug\main.o:main.cpp|| undefined reference to `event'|
    ||=== Build finished: 42 errors, 36 warnings (0 minutes, 1 seconds) ===|

  4. #4
    Expert éminent sénior
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 614
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 614
    Points : 30 626
    Points
    30 626
    Par défaut
    Salut,

    Ce qu'il y a de bien, c'est que le compilateur te donne tout plein d'avertissement avant la première erreur. Ils devraient pourtant te mettre sur la voie

    Les avertissements te signalent, en gros, que tu déclares les variables imageDeFond et suivante comme étant des variable extern tout en les initialisant (à NULL) dans le fichier d'en-tête.

    Or, le mot clé extern sert, en gros, à indiquer au compilateur qu'il existe une variable, correctement déclarée et initialisée du nom et du type indiqué "quelque part ailleurs", et qu'il peut te faire confiance à ce sujet.

    Le problème, c'est que dés que tu initialises une variable, il n'y a plus de extern qui compte, parce que ce n'est plus une simple déclaration de variable (t'inquiètes, la variable existe bel et bien "par ailleurs"), mais c'est une définition. Le mot clé extern est donc purement et simplement ignoré dans le fichier d'en-tête vu que, pour le compilateur, tu définis en réalité une variable nommée imageDeFond qui est de type "pointeur sur SDL_surface" (et, bien sur, il en va de même pour toutes les autres ).

    Du coup, lorsqu'il gère le fichier .cpp, il rencontre une première déclaration de imageDeFond dans le fichier d'en-tete et une deuxième déclaration de la même variable dans le fichier d'implémentation. C'est ce qui occasionne le message d'erreur.

    La solution est donc, tout simplement, de virer ce = NULL que je ne saurais voir dans le fichier d'en-tête pour que les déclaration extern puissent correctement jouer leur rôle.

    Ceci étant dit, on ne le répétera jamais assez, les variables globales, c'est mal et ce, pour toute une série de raisons.

    Ce que je te conseillerais volontiers, c'est de créer une structure qui regroupe les différents pointeurs sur SDL_surface sous une forme proche de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    struct SdlDatas{
        SDL_Surface *imageDeFond ;
        SDL_Surface *vert;
        SDL_Surface *blanc;
        SDL_Surface *texte;
        SDL_Surface *screen;
        SDL_Surface *piecePionBlanc;
        SDL_Surface *piecePionNoir;
        SDL_Surface *pieceRoiNoir;
        SDL_Surface *pieceRoiBlanc;
        SDL_Surface *pieceTourBlanc;
        SDL_Surface *pieceTourNoir;
        SDL_Surface *pieceFouBlanc;
        SDL_Surface *pieceFouNoir;
        SDL_Surface *pieceCavalierNoir;
        SDL_Surface *pieceCavalierBlanc;
        SDL_Surface *pieceDameNoir;
        SDL_Surface *pieceDameBlanc;
        TTF_Font *police
    };
    que tu pourrais, par exemple, transmettre par référence à la fonction load_files sous la forme de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    bool load_files(SdlDatas & datas)
    {
        //Load the image
        datas.imageDeFond = load_image( "images/pierre.jpg" );
        datas.vert = load_image("images/vert.jpg");
        datas.blanc = load_image("images/blanc.jpg");
        datas.pieceFouNoir = load_image("images/pieceFouNoir.bmp");
        datas.pieceFouBlanc = load_image("images/pieceFouBlanc.bmp");
        datas.pieceDameNoir = load_image("images/pieceDameNoir.bmp");
        datas.pieceDameBlanc = load_image("images/pieceDameBlanc.bmp");
        datas.pieceCavalierNoir = load_image("images/pieceCavalierNoir.bmp");
        datas.pieceCavalierBlanc = load_image("images/pieceCavalierBlanc.bmp");
        datas.pieceRoiNoir = load_image("images/pieceRoiNoir.bmp");
        datas.pieceRoiBlanc = load_image("images/pieceRoiBlanc.bmp");
        datas.pieceTourNoir = load_image("images/pieceTourNoir.bmp");
        datas.pieceTourBlanc = load_image("images/pieceTourBlanc.bmp");
        datas.piecePionNoir = load_image("images/piecePionNoir.bmp");
        datas.piecePionBlanc = load_image("images/piecePionBlanc.bmp");
     
        datas.police = TTF_OpenFont("calibri.ttf", 35);
     
        //If there was an error in loading the image
        if( datas.imageDeFond == NULL )
        {
            return false;
        }
     
        //If there was an error in loading the font
        if( datas.police == NULL )
        {
            return false;
        }
     
        //If everything loaded fine
        return true;
    }
    et dont tu créerais une instance unique dans ta fonction main qui deviendrait quelque chose comme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    int main( int argc, char* args[] )
    {
        int positiontx = 260;
        int positionty = 805-80;
        int positionBlancx = 300;
        int positionBlancy = 140;
        int positionVertx = 380;
        int positionVerty = 140;
     
     
        //Make sure the program waits for a quit
        bool quit = false;
     
        //Initialize
        if( init() == false )
        {
            return 1;
        }
     
        SdlDatas data;
        //Load the files
        if( load_files(datas) == false )
        {
            return 1;
        }
     
        //Apply the surface to the screen
        apply_surface( 0, 0, datas.imageDeFond, screen );
            char lettre[2]="A";
     
        for(char k='A'; k<'I'; k++)
        {
            lettre[0]=k;
            texte = TTF_RenderText_Blended(datas.police,lettre,textColor);
            apply_surface( positiontx, positionty, texte, screen);
            positionty-=80;
        }
        positiontx = 260+640+60;
        positionty = 805-80;
     
        char lettre2[2]="A";
     
        for(char k='A'; k<'I'; k++)
        {
            lettre2[0]=k;
            texte = TTF_RenderText_Blended(datas.police,lettre2,textColor);
            apply_surface( positiontx, positionty, texte, screen);
            positionty-=80;
        }
        positiontx = 330;
        positionty = 100;
     
        char chiffre[2]="1";
        for(char k='1'; k<'9'; k++)
        {
            chiffre[0]=k;
            texte = TTF_RenderText_Blended(datas.police,chiffre,textColor);
            apply_surface( positiontx, positionty, texte, screen);
            positiontx+=80;
        }
        positiontx = 330;
        positionty = 790;
     
        char chiffre2[2]="1";
        for(char k='1'; k<'9'; k++)
        {
            chiffre2[0]=k;
            texte = TTF_RenderText_Blended(datas.police,chiffre2,textColor);
            apply_surface( positiontx, positionty, texte, screen);
            positiontx+=80;
        }
     
     //If there was an error in rendering the text
        if( texte == NULL )
        {
            return 1;
        }
     
     
        do
        {
            do
            {
                apply_surface( positionBlancx, positionBlancy, datas.blanc, screen );
                positionBlancx = positionBlancx+160;
     
                apply_surface( positionVertx, positionVerty, datas.vert, screen );
                positionVertx = positionVertx+160;
     
            }while(positionBlancx < 890 && positionVertx < 975);
     
            positionBlancx = 300;
            positionBlancy = positionBlancy+160;
     
            positionVertx = 380;
            positionVerty =  positionVerty+160;
     
        }while (positionBlancy <  640+140 && positionVerty < 640+140);
     
        positionBlancx = 380;
        positionBlancy = 80+140;
        positionVertx = 300;
        positionVerty = 80+140;
     
        do
        {
            do
            {
               apply_surface( positionBlancx, positionBlancy, datas.blanc, screen );
               positionBlancx = positionBlancx+160;
     
               apply_surface( positionVertx, positionVerty, datas.vert, screen );
               positionVertx = positionVertx+160;
            }while(positionBlancx < 975 && positionVertx < 890);
     
            positionVertx = 300;
            positionVerty = positionVerty+160;
            positionBlancx = 380;
            positionBlancy = positionBlancy+160;
            }while (positionBlancy < 640+140 && positionVerty < 640+140);
     
     
        //Update the screen
        if( SDL_Flip( screen ) == -1 )
        {
            return 1;
        }
     
        //While the user hasn't quit
        //Tant que l'utilisateur n'a pas quitter
        while( quit == false )
        {
            //tant qu'il y a un evenement dans le handler
            while( SDL_PollEvent( &event ) )
            {
                //Si l'utilisateur ferme la fenetre avec le X
                if( event.type == SDL_QUIT )
                {
                    //On quitte le programme
                    quit = true;
                }
            }
        }
        clean_up();
        return 0;
    }
    (j'ai peut être pas modifié tout ce qu'il fallait... à toi de vérifier )

    Enfin, j'aurais tendance à dire que ta fonction main en fait, décidément, beaucoup trop et que tu aurais vraiment intérêt à déléguer d'avantage les responsabilités.

    En gros, chaque boucle (de "premier niveau") que tu définis dans ta fonction main pourrait avantageusement être remplacée par une fonction spécifique.

    Tu pourrais donc assez facilement te retrouver avec des fonctions proches de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    bool print_lines(SDL_surface * screen, TTF_Font *police, SDL_Color textColor){
        int positiontx = 260;
        int positionty = 805-80;
        SDL_Surface *texte;
        char lettre[2]="A";
     
        for(char k='A'; k<'I'; k++)
        {
            lettre[0]=k;
            texte = TTF_RenderText_Blended(police,lettre,textColor);
            apply_surface( positiontx, positionty, texte, screen);
            positionty-=80;
        }
        return (texte!= NULL);
    }
    bool print_columns(SDL_surface * screen, TTF_Font *police, SDL_Color textColor){
        int positiontx = 330;
        int positionty = 790;
     
        SDL_Surface *texte;
        char chiffre2[2]="1";
        for(char k='1'; k<'9'; k++)
        {
            chiffre2[0]=k;
            texte = TTF_RenderText_Blended(police,chiffre2,textColor);
            apply_surface( positiontx, positionty, texte, screen);
            positiontx+=80;
        }
        return (texte!= NULL);
    }
    bool draw_board(SDL_surface * screen, SDL_Surface * blanc, SDL_surface * vert){
        int positionBlancx = 300;
        int positionBlancy = 140;
        int positionVertx = 380;
        int positionVerty = 140;
        do
        {
            do
            {
                apply_surface( positionBlancx, positionBlancy, blanc, screen );
                positionBlancx = positionBlancx+160;
     
                apply_surface( positionVertx, positionVerty, vert, screen );
                positionVertx = positionVertx+160;
     
            }while(positionBlancx < 890 && positionVertx < 975);
     
            positionBlancx = 300;
            positionBlancy = positionBlancy+160;
     
            positionVertx = 380;
            positionVerty =  positionVerty+160;
     
        }while (positionBlancy <  640+140 && positionVerty < 640+140);
        return screen != NULL;
    }
    /* J'ai pas trop compris pourquoi tu compiais à peu près le même code deux fois...
     * Dans le doute, j'ai créé deux fonctions différentes ;)
     */
    bool draw_other(SDL_surface * screen, SDL_Surface * blanc, SDL_surface * vert){
        int positionBlancx = 380;
        int positionBlancy = 80+140;
        int positionVertx = 300;
        int positionVerty = 80+140;
        do
        {
            do
            {
               apply_surface( positionBlancx, positionBlancy, blanc, screen );
               positionBlancx = positionBlancx+160;
     
               apply_surface( positionVertx, positionVerty, vert, screen );
               positionVertx = positionVertx+160;
            }while(positionBlancx < 975 && positionVertx < 890);
     
            positionVertx = 300;
            positionVerty = positionVerty+160;
            positionBlancx = 380;
            positionBlancy = positionBlancy+160;
            }while (positionBlancy < 640+140 && positionVerty < 640+140);
            return screen != NULL;
    }
    void run(){
        while( quit == false )
        {
            //tant qu'il y a un evenement dans le handler
            while( SDL_PollEvent( &event ) )
            {
                //Si l'utilisateur ferme la fenetre avec le X
                if( event.type == SDL_QUIT )
                {
                    //On quitte le programme
                    quit = true;
                }
            }
        }
    }
    Ce qui te permettrait de limiter ta fonction main à l'appel des différentes fonctions, sous une forme qui serait très proche de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    int main( int argc, char* args[] )
    {
     
        //Make sure the program waits for a quit
        bool quit = false;
     
        //Initialize
        if( init() == false )
        {
            return 1;
        }
     
        SdlDatas data;
        //Load the files
        if( load_files(datas) == false )
        {
            return 1;
        }
     
        //Apply the surface to the screen
        apply_surface( 0, 0, datas.imageDeFond, screen );
        if(!print_lines(datas.screen, data.police, SDL_color(RR,GG,BB))){
            //mauvais, que fait-on ?
        }
        if(! print_columns(datas.screen, data.police, SDL_color(RR,GG,BB))){
            //mauvais, que fait-on ?
        }
     
     //If there was an error in rendering the text
        if( texte == NULL )
        {
            return 1;
        }
        if(! draw_board(data.screen,data.blanc,data.vert)){
            //mauvais, que fait-on ?
        }
        if(! draw_other(data.screen,data.blanc,data.vert)){
            //mauvais, que fait-on ?
        }
     
     
        //Update the screen
        if( SDL_Flip( screen ) == -1 )
        {
            return 1;
        }
     
        //While the user hasn't quit
        //Tant que l'utilisateur n'a pas quitter
        run();
        clean_up();
        return 0;
    }
    C'est un découpage très approximatif et je me suis très certainement gouré quelque part, vu que je n'ai absolument pas testé ce que je faisais et que je travaillais à coup de copier coller.

    Mais l'idée est vraiment de faire en sorte que chaque fonction ne s'occupe que d'une chose bien particulière afin de la garder la plus simple possible
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 8
    Points : 5
    Points
    5
    Par défaut
    Merci de ton aide !
    Je vais essayer de mettre tous ça en place !

  6. #6
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2013
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2013
    Messages : 8
    Points : 5
    Points
    5
    Par défaut
    Bon lorsque je mets tout comme tu m'as dit, il me sort plusieurs problemes avec les variables de la structure non trouvées...
    voici les fichiers : http://we.tl/Do6oxkqJJu
    Merci de l'aide

Discussions similaires

  1. probleme inclusions/definitions multiples
    Par RasWisdom dans le forum Débuter
    Réponses: 5
    Dernier message: 23/11/2012, 11h27
  2. Réponses: 2
    Dernier message: 24/03/2012, 09h08
  3. Probleme classique : multiple definition
    Par inddzen dans le forum C++
    Réponses: 7
    Dernier message: 08/03/2007, 15h26
  4. [web] Probleme de passe de variable qd j utilise un module TK
    Par Slippers dans le forum Interfaces Graphiques
    Réponses: 5
    Dernier message: 19/04/2005, 17h48
  5. [VB.NET] Problem de récupération de variable avec une DLL
    Par ludovic85 dans le forum Windows Forms
    Réponses: 11
    Dernier message: 19/01/2005, 11h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo