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

Author Topic: Unresolved Externals Error  (Read 1892 times)

0 Members and 1 Guest are viewing this topic.

bobross419

  • Newbie
  • *
  • Posts: 2
    • View Profile
Unresolved Externals Error
« on: June 28, 2009, 09:46:38 pm »
Code (Left off some of the function definitions, if I comment them out it doesn't change anything):

Code: [Select]

#include <SFML/window.hpp>
#include <SFML/system.hpp>
#include <SFML/graphics.hpp>
#include <iostream>


const int SQUARE_HEIGHT = 80;
const int SQUARE_WIDTH = 80;

class Space
{
public:

static bool Init()
{
if ((WhiteSpace.LoadFromFile("WhiteSquare.bmp")) && (BlackSpace.LoadFromFile("BlackSquare.bmp")))
{
return true;
}
else
{
return false;
}
}

bool IsWhite();
char GetColor();
void SetColor(char NewColor);


Space(char NewColor);


private:

static sf::Image WhiteSpace;
static sf::Image BlackSpace;

char Color;
sf::Sprite SpaceSprite;

};

Space::Space(char NewColor):Color(NewColor)
{
if (NewColor == 'w')
{
SpaceSprite.SetImage(WhiteSpace);
}
else
{
SpaceSprite.SetImage(BlackSpace);
}
}



Errors:
Code: [Select]

1>Test2.obj : error LNK2001: unresolved external symbol "private: static class sf::Image Space::BlackSpace" (?BlackSpace@Space@@0VImage@sf@@A)
1>Test2.obj : error LNK2001: unresolved external symbol "private: static class sf::Image Space::WhiteSpace" (?WhiteSpace@Space@@0VImage@sf@@A)



Linker Input:
Code: [Select]
sfml-system-d.lib
sfml-window-d.lib
sfml-graphics-d.lib


Preprocessor Definitions:
Code: [Select]
SFML_DYNAMIC
WIN32
_CONSOLE
_DEBUG


This is basically the same thing that was done in this tutorial (http://www.sfml-dev.org/tutorials/1.5/graphics-sprite.php) in the bottom section for Image and Sprites Management.  If I remove the constructor everything compiles fine.  I've tried running the Init() function in the Main() function, but this didn't change anything.  I originally was passing the filenames, but changed this to hardcoded filenames as a way of testing.

I've read quite a few posts and done quite a bit of searching, everyone else with this issue was able to resolve it by either including the sfml-window.lib to the linker or adding the SFML_DYNAMIC to the preprocessor definitions.

I'm using VC++2008 Express Edition, on Windows Vista Ultimate 64.

I've added the sfml-graphics-d.dll, sfml-window-d.dll, and sfml-system-d.dll files to every folder and subfolder of this project.  I've done the same with the BlackSquare.bmp and WhiteSquare.bmp files.

I'm trying to take the tutorial information and put it to a more practical use to learn a bit more about SFML, but these linkers and stuff are making me bang my head against the wall and getting me pretty discouraged.  I've already uninstalled the SDL and GDK libraries for very similar reasons, no matter what I did I couldn't get them to work :(  I really like the way SFML is setup and want to get past this hurdle.

Thanks for any help you guys can provide.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unresolved Externals Error
« Reply #1 on: June 28, 2009, 11:27:46 pm »
This is basic C++, a static member variable has to be defined in a .cpp file. You can learn it in any C++ tutorial that you can find with Google ;)
Code: [Select]
myclass.hpp
-----------

class MyClass
{
    static sf::Image var;
};


Code: [Select]
myclass.cpp
-----------

#include "myclass.hpp"

sf::Image MyClass::var;
Laurent Gomila - SFML developer

bobross419

  • Newbie
  • *
  • Posts: 2
    • View Profile
Unresolved Externals Error
« Reply #2 on: June 29, 2009, 01:58:06 am »
Ahh :)

Thanks much Laurent.

All my background is Java, so I'm still learning the intricacies of C++

 

anything