Привет, ЛОР! Разбираюсь тут с SDL, вот код:
#include "SDL/SDL.h"
#include <string>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
SDL_Surface *message = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *load_image( std::string filename ) {
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = SDL_LoadBMP( filename.c_str() );
if( loadedImage != NULL )
{
optimizedImage = SDL_DisplayFormat( loadedImage );
SDL_FreeSurface(loadedImage);
}
return optimizedImage;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface( source, NULL, destination, &offset );
}
int main( int argc, char* args[] ) {
if ( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return 1;
}
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
if ( screen == NULL )
{
return 1;
}
SDL_WM_SetCaption( "Hello World", NULL );
message = load_image( "hello.bmp" );
background = load_image( "background.bmp" );
apply_surface( 0, 0, background, screen );
apply_surface( 320, 0, background, screen );
apply_surface( 0, 240, background, screen );
apply_surface( 320, 240, background, screen );
apply_surface( 180, 140, message, screen );
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
SDL_Delay( 2000 );
SDL_FreeSurface( message );
SDL_FreeSurface( background );
SDL_Quit();
return 0;
}
Если компилировать через g++:
g++ main.cxx -lSDL
gcc main.cxx -lSDL
/tmp/cckr6Whs.o: In function `load_image(std::string)':
main.cpp:(.text+0x24): undefined reference to `std::string::c_str() const'
/tmp/cckr6Whs.o: In function `main':
main.cpp:(.text+0x133): undefined reference to `std::allocator<char>::allocator()'
main.cpp:(.text+0x148): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
main.cpp:(.text+0x167): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x173): undefined reference to `std::allocator<char>::~allocator()'
main.cpp:(.text+0x17f): undefined reference to `std::allocator<char>::allocator()'
main.cpp:(.text+0x194): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
main.cpp:(.text+0x1b3): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x1bf): undefined reference to `std::allocator<char>::~allocator()'
main.cpp:(.text+0x2d1): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x2e2): undefined reference to `std::allocator<char>::~allocator()'
main.cpp:(.text+0x2fc): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.cpp:(.text+0x30d): undefined reference to `std::allocator<char>::~allocator()'
/tmp/cckr6Whs.o:(.eh_frame+0x4b): undefined reference to `__gxx_personality_v0'
collect2: ошибка: выполнение ld завершилось с кодом возврата 1
Собственно вопрос: а почему так?