Thread: Problem With std::string in Codeblocks.

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    66

    Problem With std::string in Codeblocks.

    Hello guys!
    When I tried to compile my code in CodeBlocks, configuration set to release, I get hundreds of this error:

    undefined reference to `__gnu_cxx::__exchange_and_add(int volatile*, int)'
    "undefined reference to `std::string::_Rep::_S_empty_rep_storage"

    This doesn't happen when I set my configuration to debug, but I'm wondering why this problem doesn't happen in MinGW Developer Studio in any configuration.

    I suspect that this is an error in my linker options, but I tried changing all options without any result.

    Can anyone help me?

    this is the code:

    Code:
    #include "cMenu.h"
    
    cMenu cMenu::a_menu;
    
    cMenu::cMenu()
    {
    	Surf_Background = NULL;
    	Surf_Mark       = NULL;
    	Surf_Thumbs     = NULL;
    	Surf_Buttons    = NULL;
    	
    	MODE       = FOURFOUR;
    	CAT        = 0;
    	numCats    = 0;
    	numButtons = 0;
    }
    
    bool cMenu::OnInit()
    {
    	if((Surf_Background = CSurface::OnLoad("gfx/menu.jpg")) == NULL)
    	{
    		MessageBox(GetActiveWindow(), IMG_GetError(), "SDL Resource Load Failure", MB_OK | MB_ICONEXCLAMATION);
    		return false;
    	}
    	
    	if((Surf_Mark = CSurface::OnLoad("gfx/ok.png")) == NULL)
    	{
    		MessageBox(GetActiveWindow(), IMG_GetError(), "SDL Resource Load Failure", MB_OK | MB_ICONEXCLAMATION);
    		return false;		
    	}
    	
    	std::ifstream CardSets("CAT/CARDSETS.MCAT");
    	
    	if(!CardSets.is_open())
    	{
    		MessageBox(GetActiveWindow(), "CardSet Information File Not Found!", "Game Error", MB_OK | MB_ICONEXCLAMATION);
    		return false;
    	}
    	
    	CardSets >> numCats;
    	
    	CardSets.ignore();
    	
    	for(int i = 0;i < numCats;++i)
    	{
    		cCategory newCategory;
    		CategoryList.push_back(newCategory);
    	}
    	
    	for(int i = 0;i < numCats;++i)
    	{
    		CardSets.ignore();
    		std::getline(CardSets, CategoryList[i].Title    , ';');
    		std::getline(CardSets, CategoryList[i].CardFile , ';');
    		std::getline(CardSets, CategoryList[i].ThumbFile, '\n');
    	}
    	
    	CardSets.close();
    	
    	Surf_Thumbs = new SDL_Surface*[numCats];
    	
    	for(int i = 0;i < numCats;++i)
    	{
    		if((Surf_Thumbs[i] = CSurface::OnLoad(CategoryList[i].ThumbFile.c_str())) == NULL)
    		{
    			MessageBox(GetActiveWindow(), IMG_GetError(), "SDL Resource Load Failure", MB_OK | MB_ICONEXCLAMATION);
    			return false;	
    		}
    	}
    	
    	for(unsigned i = 0;i < MENU_CHECK;++i)
    	{
    		Button newButton(Surf_Mark, 640, 100 + (i * BUTTON_HEIGHT), BUTTON_WIDTH, BUTTON_HEIGHT);
    		CheckList.push_back(newButton);
    	}
    	
    	std::ifstream ButtonData("CAT/MENUBUTTONS.MBUT");
    	
    	if(!ButtonData.is_open())
    	{
    		MessageBox(GetActiveWindow(), "ButtonData Information File Not Found!", "Game Error", MB_OK | MB_ICONEXCLAMATION);
    		return false;
    	}
    	
    	ButtonData >> numButtons;
    	ButtonData.ignore();
    	
    	Surf_Buttons = new SDL_Surface*[numButtons];
    	
    	for(int i = 0;i < numButtons;++i)
    	{
    		std::string Path;
    		std::getline(ButtonData, Path, ';');
    		
    		if((Surf_Buttons[i] = CSurface::OnLoad(Path.c_str())) == NULL)
    		{
    			MessageBox(GetActiveWindow(), IMG_GetError(), "SDL Resource Load Failure", MB_OK | MB_ICONEXCLAMATION);
    			return false;	
    		}
    		
    		int X, Y, W, H, V;
    		
    		ButtonData >> X >> Y >> W >> H >> V;
    		ButtonData.ignore();
    		
    		Button newButton(Surf_Buttons[i], X, Y, W, H, V);
    		ButtonList.push_back(newButton);
    	}
    	
    	ButtonData.close();
    	
    	return true;
    }
    
    void cMenu::OnCleanUp()
    {
    	SDL_FreeSurface(Surf_Background);
    	Surf_Background = NULL;
    	
    	SDL_FreeSurface(Surf_Mark);
    	Surf_Mark = NULL;
    	
    	for(int i = 0;i < numButtons;++i)
    	{
    		SDL_FreeSurface(Surf_Buttons[i]);
    		Surf_Buttons[i] = NULL;
    	}
    	
    	delete [] Surf_Buttons;
    	
    	for(int i = 0;i < numCats;++i)
    	{
    		SDL_FreeSurface(Surf_Thumbs[i]);
    		Surf_Thumbs[i] = NULL;
    	}
    	
    	delete [] Surf_Thumbs;
    	
    	CategoryList.clear();
    	CheckList.clear();
    	ButtonList.clear();
    }
    
    void cMenu::OnPause()
    {
    }
    
    void cMenu::OnResume()
    {
    }
    
    void cMenu::OnEvent(cGameEngine *Memory_Game)
    {
    	SDL_Event event;
    
    	if(SDL_WaitEvent(&event))
    	{
    		switch(event.type)
    		{
    			case SDL_QUIT :
    			{
    				Memory_Game -> Quit();
    				break;
    			}
    			case SDL_KEYDOWN :
    			{
    				switch(event.key.keysym.sym)
    				{
    					case SDLK_ESCAPE : Memory_Game -> Quit();break;
    					case SDLK_RETURN :
    					{
    						cGameInstance::Instance() -> SetMode(CategoryList[CAT].CardFile, MODE);
    						Memory_Game -> PushState(cGameInstance::Instance());
    						break;
    					}
    					case SDLK_DOWN  : MODE += MODE < EIGHTEIGHT?  1 : 0;break;
    					case SDLK_UP    : MODE -= MODE > FOURFOUR?    1 : 0;break;
    					case SDLK_LEFT  : CAT  -= CAT  > 0?           1 : 0;break;
    					case SDLK_RIGHT : CAT  += CAT  < numCats - 1? 1 : 0;break;
    					default : break;
    				}
    			}		
    			case SDL_MOUSEBUTTONDOWN :
    			{
    				switch(event.button.button)
    				{
    					case SDL_BUTTON_LEFT :
                        {
    						for(unsigned i = 0;i < CheckList.size();++i)
    						{
    							CheckList[i].STATUS = BTN_INACTIVE;
    							if(event.button.x >= CheckList[i].X && event.button.x <= CheckList[i].X + CheckList[i].Width)
    							{
    								if(event.button.y >= CheckList[i].Y && event.button.y <= CheckList[i].Y + CheckList[i].Height)
    								{
    									MODE = i;
    								}
    							}
    						}
    						for(unsigned i = 0;i < ButtonList.size();++i)
    						{
    							if(event.button.x >= ButtonList[i].X && event.button.x <= ButtonList[i].X + ButtonList[i].Width)
    							{
    								if(event.button.y >= ButtonList[i].Y && event.button.y <= ButtonList[i].Y + ButtonList[i].Height)
    								{
    									ButtonList[i].STATUS = BTN_ACTIVE;
    								}
    							}
    						}
    						break;
    					}
    				}
    			}
    			break;
    			case SDL_MOUSEBUTTONUP :
    			{
    				switch(event.button.button)
    				{
    					case SDL_BUTTON_LEFT :
    					{
    						for(unsigned i = 0;i < ButtonList.size();++i)
    						{
    							ButtonList[i].STATUS = BTN_INACTIVE;
    							
    							if(event.button.x >= ButtonList[i].X && event.button.x <= ButtonList[i].X + ButtonList[i].Width)
    							{
    								if(event.button.y >= ButtonList[i].Y && event.button.y <= ButtonList[i].Y + ButtonList[i].Height)
    								{
    									switch(ButtonList[i].Value)
    									{
    										case LEFT  : CAT -= CAT > 0? 1 : 0;break;
    										case RIGHT : CAT += CAT < numCats - 1? 1 : 0;break;
    										case PLAY  : 
    										{
    											cGameInstance::Instance() -> SetMode(CategoryList[CAT].CardFile, MODE);
    											Memory_Game -> PushState(cGameInstance::Instance());
    											break;
    										}
    									}
    								}
    							}
    						}
    						break;
    					}
    				}
    			}		
    			break;		
    			default : break;
    		}
    	}
    }
    
    void cMenu::OnLoop()
    {
    	CheckList[MODE].STATUS = BTN_ACTIVE;
    }
    
    void cMenu::OnRender(SDL_Surface *Surf_Display)
    {
        if(Surf_Display == NULL || Surf_Background == NULL)
            return;
    
    	CSurface::OnDraw(Surf_Display, Surf_Background, 0, 0);
    	
    	int Height = TTF_FontHeight(CFont::FontControl.FontList[CFont::FontControl.ResPublica18]);
    	for(unsigned i = FOURFOUR;i <= EIGHTEIGHT;++i)
    	{
    		CFont::FontControl.OnWrite(Surf_Display, Modes[i], CFont::FontControl.ResPublica18, 670, 100 + (i * Height), 0, 0, 0);
    	}
    	
    	CFont::FontControl.OnWrite(Surf_Display, CategoryList[CAT].Title.c_str(), CFont::FontControl.ResPublica24, 220, 510, 0, 0, 0);
    	
    	for(unsigned i = 0;i < CheckList.size();++i)
    	{
    		CheckList[i].OnRender(Surf_Display);
    	}
    	
    	for(unsigned i = 0;i < ButtonList.size();++i)
    	{
    		ButtonList[i].OnRender(Surf_Display);
    	}
    	
    	CSurface::OnDraw(Surf_Display, Surf_Thumbs[CAT], THUMB_X, THUMB_Y);
    }
    
    cMenu* cMenu::Instance()
    {
    	return &a_menu;
    }
    
    const char* cMenu::Modes[11] = 
    {
    	"4 x 4",
    	"4 x 5",
    	"5 x 4",
    	"6 x 5",
    	"6 x 6",
    	"6 x 7",
    	"6 x 8",
    	"7 x 6",
    	"7 x 8",
    	"8 x 7",
    	"8 x 8"
    };

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I don't know where you would put this in Code::Blocks's configuration, but try to pass -march=i686 (or any valid value except i386, really) to the compiler. Although, given that MinGW is still a 3.x series compiler, that might not help.

    What are your current compilation and linking command lines?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    66
    Nope, adding -march=i686 doesn't help..

    For the release config, I have only selected -s and - Wall

    MinGW Developer Studio and CodeBlocks I'm using share the same libraries, so why doesn't it work in CodeBlocks but well in MinGW Developer Studio?

    EDIT:
    Setting the linker options for Release the same as the linker options for debug doesn't help either.
    Last edited by ThLstN; 08-24-2008 at 07:52 AM.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    66
    Nevermind, fixed by removing -O2, missed that option.

    Thx guys!

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    -O2 is pretty much the point of a release configuration, though. That, and the lack of debug information.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. Code::Blocks problem
    By eaane74 in forum C++ Programming
    Replies: 6
    Last Post: 05-24-2007, 07:24 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM