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

SDL Discussion :

erreur pour la ligne de commande gcc


Sujet :

SDL

  1. #1
    Membre éclairé
    Homme Profil pro
    sans emploi
    Inscrit en
    Février 2014
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : sans emploi
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2014
    Messages : 365
    Par défaut erreur pour la ligne de commande gcc
    Bonjour,

    Je m'initie à la SDL2 avec 1 tuto en ligne

    Voici le lien http://lazyfoo.net/tutorials/SDL/04_...sses/index.php

    Le script est

    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
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    /*This source code copyrighted by Lazy Foo' Productions (2004-2020)
    and may not be redistributed without written permission.*/
     
    //Using SDL, standard IO, and strings
    #include <SDL.h>
    #include <stdio.h>
    #include <string>
     
    //Screen dimension constants
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 480;
     
    //Key press surfaces constants
    enum KeyPressSurfaces
    {
    	KEY_PRESS_SURFACE_DEFAULT,
    	KEY_PRESS_SURFACE_UP,
    	KEY_PRESS_SURFACE_DOWN,
    	KEY_PRESS_SURFACE_LEFT,
    	KEY_PRESS_SURFACE_RIGHT,
    	KEY_PRESS_SURFACE_TOTAL
    };
     
    //Starts up SDL and creates window
    bool init();
     
    //Loads media
    bool loadMedia();
     
    //Frees media and shuts down SDL
    void close();
     
    //Loads individual image
    SDL_Surface* loadSurface( std::string path );
     
    //The window we'll be rendering to
    SDL_Window* gWindow = NULL;
     
    //The surface contained by the window
    SDL_Surface* gScreenSurface = NULL;
     
    //The images that correspond to a keypress
    SDL_Surface* gKeyPressSurfaces[ KEY_PRESS_SURFACE_TOTAL ];
     
    //Current displayed image
    SDL_Surface* gCurrentSurface = NULL;
     
    bool init()
    {
    	//Initialization flag
    	bool success = true;
     
    	//Initialize SDL
    	if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    	{
    		printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
    		success = false;
    	}
    	else
    	{
    		//Create window
    		gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
    		if( gWindow == NULL )
    		{
    			printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
    			success = false;
    		}
    		else
    		{
    			//Get window surface
    			gScreenSurface = SDL_GetWindowSurface( gWindow );
    		}
    	}
     
    	return success;
    }
     
    bool loadMedia()
    {
    	//Loading success flag
    	bool success = true;
     
    	//Load default surface
    	gKeyPressSurfaces[ KEY_PRESS_SURFACE_DEFAULT ] = loadSurface( "04_key_presses/press.bmp" );
    	if( gKeyPressSurfaces[ KEY_PRESS_SURFACE_DEFAULT ] == NULL )
    	{
    		printf( "Failed to load default image!\n" );
    		success = false;
    	}
     
    	//Load up surface
    	gKeyPressSurfaces[ KEY_PRESS_SURFACE_UP ] = loadSurface( "04_key_presses/up.bmp" );
    	if( gKeyPressSurfaces[ KEY_PRESS_SURFACE_UP ] == NULL )
    	{
    		printf( "Failed to load up image!\n" );
    		success = false;
    	}
     
    	//Load down surface
    	gKeyPressSurfaces[ KEY_PRESS_SURFACE_DOWN ] = loadSurface( "04_key_presses/down.bmp" );
    	if( gKeyPressSurfaces[ KEY_PRESS_SURFACE_DOWN ] == NULL )
    	{
    		printf( "Failed to load down image!\n" );
    		success = false;
    	}
     
    	//Load left surface
    	gKeyPressSurfaces[ KEY_PRESS_SURFACE_LEFT ] = loadSurface( "04_key_presses/left.bmp" );
    	if( gKeyPressSurfaces[ KEY_PRESS_SURFACE_LEFT ] == NULL )
    	{
    		printf( "Failed to load left image!\n" );
    		success = false;
    	}
     
    	//Load right surface
    	gKeyPressSurfaces[ KEY_PRESS_SURFACE_RIGHT ] = loadSurface( "04_key_presses/right.bmp" );
    	if( gKeyPressSurfaces[ KEY_PRESS_SURFACE_RIGHT ] == NULL )
    	{
    		printf( "Failed to load right image!\n" );
    		success = false;
    	}
     
    	return success;
    }
     
    void close()
    {
    	//Deallocate surfaces
    	for( int i = 0; i < KEY_PRESS_SURFACE_TOTAL; ++i )
    	{
    		SDL_FreeSurface( gKeyPressSurfaces[ i ] );
    		gKeyPressSurfaces[ i ] = NULL;
    	}
     
    	//Destroy window
    	SDL_DestroyWindow( gWindow );
    	gWindow = NULL;
     
    	//Quit SDL subsystems
    	SDL_Quit();
    }
     
    SDL_Surface* loadSurface( std::string path )
    {
    	//Load image at specified path
    	SDL_Surface* loadedSurface = SDL_LoadBMP( path.c_str() );
    	if( loadedSurface == NULL )
    	{
    		printf( "Unable to load image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
    	}
     
    	return loadedSurface;
    }
     
     
    int main( int argc, char* args[] )
    {
    	//Start up SDL and create window
    	if( !init() )
    	{
    		printf( "Failed to initialize!\n" );
    	}
    	else
    	{
    		//Load media
    		if( !loadMedia() )
    		{
    			printf( "Failed to load media!\n" );
    		}
    		else
    		{	
    			//Main loop flag
    			bool quit = false;
     
    			//Event handler
    			SDL_Event e;
     
    			//Set default current surface
    			gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_DEFAULT ];
     
    			//While application is running
    			while( !quit )
    			{
    				//Handle events on queue
    				while( SDL_PollEvent( &e ) != 0 )
    				{
    					//User requests quit
    					if( e.type == SDL_QUIT )
    					{
    						quit = true;
    					}
    					//User presses a key
    					else if( e.type == SDL_KEYDOWN )
    					{
    						//Select surfaces based on key press
    						switch( e.key.keysym.sym )
    						{
    							case SDLK_UP:
    							gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_UP ];
    							break;
     
    							case SDLK_DOWN:
    							gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_DOWN ];
    							break;
     
    							case SDLK_LEFT:
    							gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_LEFT ];
    							break;
     
    							case SDLK_RIGHT:
    							gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_RIGHT ];
    							break;
     
    							default:
    							gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_DEFAULT ];
    							break;
    						}
    					}
    				}
     
    				//Apply the current image
    				SDL_BlitSurface( gCurrentSurface, NULL, gScreenSurface, NULL );
     
    				//Update the surface
    				SDL_UpdateWindowSurface( gWindow );
    			}
    		}
    	}
     
    	//Free resources and close SDL
    	close();
     
    	return 0;
    }
    J utilise le Terminal de Visual Studio Code pour le compiler
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    // commande
    //----------
    cd C:\Users\...\Desktop\visual_studio_code_sdl\tuto_Lazy_Foo_Productions\04_key_presses
    gcc src/main.cpp -o bin/nom_projet -I include -L lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image
    bin\nom_projet.exe
    Le message d erreur suivant apparait pour la ligne de commande gcc
    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
    gcc src/main.cpp -o bin/nom_projet -I include -L lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image 
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0xd1): undefined reference to `std::allocator<char>::allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0xeb): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x10a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x116): undefined reference to `std::allocator<char>::~allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x141): undefined reference to `std::allocator<char>::allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x15b): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x17a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x186): undefined reference to `std::allocator<char>::~allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x1b1): undefined reference to `std::allocator<char>::allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x1ca): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x1e7): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x1f3): undefined reference to `std::allocator<char>::~allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x21e): undefined reference to `std::allocator<char>::allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x238): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x257): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x263): undefined reference to `std::allocator<char>::~allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x291): undefined reference to `std::allocator<char>::allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x2ae): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x2cd): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x2dc): undefined reference to `std::allocator<char>::~allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x316): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x327): undefined reference to `std::allocator<char>::~allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x341): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x352): undefined reference to `std::allocator<char>::~allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x36b): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x37c): undefined reference to `std::allocator<char>::~allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x396): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x3a7): undefined reference to `std::allocator<char>::~allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x3c1): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x3d5): undefined reference to `std::allocator<char>::~allocator()'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x47f): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.text+0x4b7): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const'
    C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccTUJ5jN.o:main.cpp:(.xdata+0x1c): undefined reference to `__gxx_personality_seh0'
    collect2.exe: error: ld returned 1 exit status
    Merci pour votre aide
    Cordialement

  2. #2
    Rédacteur/Modérateur


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

    Informations professionnelles :
    Activité : Network game programmer

    Informations forums :
    Inscription : Juin 2010
    Messages : 7 147
    Billets dans le blog
    4
    Par défaut
    gcc c'est pas le compilateur C ? Et g++ pour le C++ ?
    Vu ton code, tu peux très bien faire ça en C, pas grand intérêt d'utiliser que std::string ainsi si c'est pour garder tout le reste du C.
    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
    Membre éclairé
    Homme Profil pro
    sans emploi
    Inscrit en
    Février 2014
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : sans emploi
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2014
    Messages : 365
    Par défaut
    Merci

    En langage C++ ça marche en changeant gcc par g++

    Si on veut lancer la compilation avec gcc et donc en c:
    je remplace:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    en c++	                =>	en c
    std::string	        =>	char *
    bool			=>	int
    true			=>	1 (!=0)
    false		        =>	0
    j obtiens le message d erreur suivant
    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
    PS C:\Users\...\Desktop\visual_studio_code_sdl\tuto_Lazy_Foo_Productions\projet_sdl_Lesson_04_key_presses> gcc src/main.c -o bin/nom_projet_c -I include -L lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image
    In file included from include/SDL_video.h:34,
                     from include/SDL_events.h:33,
                     from include/SDL.h:41,
                     from src/main.c:13:
    src/main.c: In function 'loadSurface':
    src/main.c:154:48: error: request for member 'c_str' in something not a structure or union
      154 |  SDL_Surface* loadedSurface = SDL_LoadBMP( path.c_str() );
          |                                                ^
    include/SDL_surface.h:353:59: note: in definition of macro 'SDL_LoadBMP'
      353 | #define SDL_LoadBMP(file)   SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
          |                                                           ^~~~
    src/main.c:157:59: error: request for member 'c_str' in something not a structure or union
      157 |   printf( "Unable to load image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
          |                                                           ^

    c_str() est une fonction qui renvoie un pointeur sur la chaine

    Que signifie "path" en c j ai pas trouvé sur le net: le chemin d accès? c est 1 mot clé?

    Comment interpreter "path.c_str()"?

  4. #4
    Expert confirmé
    Avatar de Kannagi
    Homme Profil pro
    cyber-paléontologue
    Inscrit en
    Mai 2010
    Messages
    3 226
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cyber-paléontologue

    Informations forums :
    Inscription : Mai 2010
    Messages : 3 226
    Par défaut
    ici path est une class , donc path.c_str() , est ce qui renvoie une chaîne de caractère du type C.
    En C on aurait tout simplement écrit "path".

Discussions similaires

  1. Réponses: 10
    Dernier message: 09/02/2010, 10h28
  2. Méthode de parsing pour une ligne de commande
    Par BiM dans le forum Langage
    Réponses: 12
    Dernier message: 27/07/2009, 16h40
  3. Probleme ligne de commande gcc
    Par Div Buchannon dans le forum Débuter
    Réponses: 16
    Dernier message: 13/03/2009, 14h11
  4. Créer un executable pour la ligne de commande
    Par buzzkaido dans le forum Eclipse Platform
    Réponses: 0
    Dernier message: 07/12/2007, 12h37
  5. Votre ligne de commande gcc
    Par sorry60 dans le forum Autres éditeurs
    Réponses: 11
    Dernier message: 16/11/2005, 16h22

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