[Solved] How can I solve this error? :S

Started by
4 comments, last by Zahlman 17 years, 9 months ago
Hi there! I'm making a pong clone with SDL. I've copied a function that worked on a tetris clone that I tried to make, but now there's a linkin' error: [Linker error] undefined reference to `std::string::c_str() const' [Linker error] undefined reference to `__gxx_personality_sj0' [Linker error] undefined reference to `std::allocator<char>::allocator()' [Linker error] undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' [Linker error] undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' [Linker error] undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' [Linker error] undefined reference to `std::allocator<char>::~allocator()' [Linker error] undefined reference to `std::allocator<char>::~allocator()' [Linker error] undefined reference to `std::allocator<char>::allocator()' [Linker error] undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' And more of the same kind of errors. What's happening? I post my little function here:

SDL_Surface * LoadImage( std::string filename )
{
    SDL_Surface * loadedImage = NULL;
    SDL_Surface * optimizedImage = NULL;
    
    loadedImage = IMG_Load( filename.c_str() );
    
    if ( loadedImage != NULL )
    {
        optimizedImage = SDL_DisplayFormat( loadedImage );
        
        SDL_FreeSurface( loadedImage );
    }
    
    Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF );
    
    SDL_SetColorKey( optimizedImage, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey );
    
    return optimizedImage;
}


Everything at Projects options is ok! parameters and directories are ok too! what's going on? Thanks in advance :) [Edited by - GutyGu on July 19, 2006 3:04:57 PM]
Advertisement
As those look like gcc errors, did you link against libstdc++?
It works now! thank you! but when I made my tetris clone I didn't have to link that library. Why does it happend?
Possibly when you made your previous application you used g++ instead of gcc to do the build step. Without knowing more about your development environment it's hard to say anything further.
I'm using DevC++ 4.9.9.2 . I didn't change anything! I created a new project and that's it. I Don't know what happened.

Thanks a lot for your help! :D
Compilers sometimes make educated guesses about whether your code is supposed to be C code or C++ code. If it doesn't find any C++-only constructs, it might assume C.

Anyway, "__gxx_personality_sj0" in the linker errors is usually a big red warning sign about this problem. If you can, check the makefile that Dev-C++ generated, and see that it asks for 'gxx' or 'g++' to be used instead of 'gcc'. (You could fix it if it's wrong, but if Dev-C++ is anything like other IDEs I've used, it will probably just change it right back. You'll need to figure out how to tell Dev-C++ that you really want a C++ project. I don't use it myself so I couldn't tell you how, sorry.)

This topic is closed to new replies.

Advertisement