I'm working with Cocos2D and I created a Singleton C++ class that will store Game Settings information. This is what my class looks like:
#include <cstddef>
#ifndef __pyramidofdoom__GameSettings__
#define __pyramidofdoom__GameSettings__
#endif /* defined(__pyramidofdoom__GameSettings__) */
class GameSettings {
private:
static GameSettings* mGameSettings;
GameSettings(){ mGameSettings = this; }
int rowSelected = 0;
public:
GameSettings *getInstance() {
if (mGameSettings == NULL)
mGameSettings = new GameSettings();
return mGameSettings;
};
int getSelectedRow() { return rowSelected; }
void setSelectedRow(int row) { rowSelected = row;}
};
This is how I use it in cocos2D mm file:
GameSettings *gameSettings = gameSettings->getInstance();
if(multi)
gameSettings->setSelectedRow(3);
else
gameSettings->setSelectedRow(1);
Seems basic enough to have everything working fine.
This is the error I'm getting when I try to build now:
Undefined symbols for architecture i386:
"GameSettings::mGameSettings", referenced from:
GameSettings::getInstance() in GameLayer-E06C3150ABD8625A.o
GameSettings::GameSettings() in GameLayer-E06C3150ABD8625A.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I made sure that the cpp/h file is included for Compile Sources under Build Phases. I also added libc++ Library to see if that would fix it.