Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Undefined symbols error when calling functions  (Read 1628 times)

0 Members and 1 Guest are viewing this topic.

Noirad

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • www.darionmccoy.com
Undefined symbols error when calling functions
« on: December 26, 2013, 09:40:10 am »
I'm a beginner testing out manipulating sprites by testing the code from http://sfml-dev.org/tutorials/1.6/graphics-sprite.php Besides the use of texture instead of image, it is a direct copy/paste.

class Missile
{
    public :
   
    static bool Init(const std::string& ImageFile)
    {
        return Texture.loadFromFile(ImageFile);
    }
   
    Missile()
    {
        Sprite.setTexture(Texture); // every sprite uses the same unique image
    }
   
    private :
   
    static sf::Texture Texture; // shared by every instance
   
    sf::Sprite Sprite; // one per instance
};
 

And calling if through a statement in the game loop ...

if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space)
            {
                Missile Bullet;
                Bullet.Init("spike.png");
               
            }
 

The class definition is fine, but once I call it, I receive this error:

Undefined symbols for architecture x86_64:
  "Missile::Texture", referenced from:
      Missile::Init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.o
      Missile::Missile() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

 

Searching around for solutions, I attempted to add the class name before the function prototypes/definitions (static bool Missile::Init(const std::string& ImageFile)) even though it is inside the class already .... of course I get an extra qualification error. Is this a linker issue? I am using mac OSX 10.8, Xcode 5.

Thanks in advance for the help, it is very much appreciated.
twitter/tumblr: @darionmccoy

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Undefined symbols error when calling functions
« Reply #1 on: December 26, 2013, 09:44:44 am »
Static member variables need to be defined (yours is just declared). Google "C++ static member" for more details, this is basic C++ stuff.
Laurent Gomila - SFML developer

Noirad

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • www.darionmccoy.com
Re: Undefined symbols error when calling functions
« Reply #2 on: December 27, 2013, 04:12:43 am »
Egghh ... hated to be that guy. Thank you, Laurent.
twitter/tumblr: @darionmccoy

 

anything