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

Author Topic: Unresolved external symbol "public: static class sf::Image *  (Read 4086 times)

0 Members and 1 Guest are viewing this topic.

timo777

  • Newbie
  • *
  • Posts: 37
    • View Profile
Unresolved external symbol "public: static class sf::Image *
« on: December 24, 2012, 05:51:14 pm »
I have got a problem. I don't know if this is a sign I got to recompile SFML or I just created a bug myself. It gives this error:

1>CImageHandler.obj : error LNK2001: unresolved external symbol "public: static class sf::Image * CImageHandler::ImageList" (?ImageList@CImageHandler@@2PAVImage@sf@@A)
1><*private*>\Game\Debug\Client.exe : fatal error LNK1120: 1 unresolved externals

The relevant code is:

void CImageHandler::OnInit(){
        sf::Image               Image;

        Image.loadFromFile("Back.png");

        ImageList[0]=Image;  
}

And I defined it like this in the header file:

static sf::Image                        ImageList[100];

I am using SFML 2.0 with my AMD graphics card with the dynamic version. Say if I forgot something... :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Unresolved external symbol "public: static class sf::Image *
« Reply #1 on: December 24, 2012, 05:56:25 pm »
Yes, you forgot the definition of the ImageList variable (you only have its declaration). Type "C++ static member" in Google if you want more details, this is basic C++ stuff ;)
Laurent Gomila - SFML developer

timo777

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Unresolved external symbol "public: static class sf::Image *
« Reply #2 on: December 24, 2012, 06:02:52 pm »
Okay, but how can you initalize an sf::Image array?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Unresolved external symbol "public: static class sf::Image *
« Reply #3 on: December 25, 2012, 12:07:24 am »
Okay, but how can you initalize an sf::Image array?
Use a std::vector<sf::Image> or even better std::vector<std::unique_ptr<sf::Image>> instead and then you can simply emplace() (C++11) or push_back() the new elements. If this is all unfamiliar to you, then it's strongly advised to get a good C++ book and specially take a look at the STL part.

Also are you sure you want to use sf::Image and not sf::Texture? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

timo777

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Unresolved external symbol "public: static class sf::Image *
« Reply #4 on: December 25, 2012, 12:38:35 am »
Okay, thank you. That looks a good idea and I forgot that you can better use sf:Texture's.

It's not unfamilair, I only tought of an array, I don't know why... And you don't need a book, http://www.cplusplus.com/ is all you need... ;)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Unresolved external symbol "public: static class sf::Image *
« Reply #5 on: December 25, 2012, 01:03:30 am »
And you don't need a book, http://www.cplusplus.com/ is all you need... ;)
...for the beginning. It's a nice site and all, but if you want depth and professional advice you're better off with something like The C++ Programming Language and Effective C++. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

timo777

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Unresolved external symbol "public: static class sf::Image *
« Reply #6 on: December 25, 2012, 11:56:05 am »
I finally got it working. :)

But now I have a new problem...

When I run the program I get:

Unhandled exception at 0x5AB12382 (sfml-graphics-d-2.dll) in Client.exe: 0xC0000094: Integer division by zero.

I don't know for sure if the texture is loaded proberly on the sprite because the error happens at
Window.draw(Sprite);
So can you check if a sprite or texture is valid before you draw? I haven't seen that because everything looks a void...

Edit: found this "It is important to note that the sf::Sprite instance doesn't copy the texture that it uses, it only keeps a reference to it. Thus, a sf::Texture must not be destroyed while it is used by a sf::Sprite (i.e. never write a function that uses a local sf::Texture instance for creating a sprite).". I will test it without the function...
« Last Edit: December 25, 2012, 12:32:03 pm by timo777 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Re: Unresolved external symbol "public: static class sf::Image *
« Reply #7 on: December 25, 2012, 12:30:50 pm »
I don't know for sure if the texture is loaded proberly on the sprite because the error happens at
Window.draw(Sprite);
So can you check if a sprite or texture is valid before you draw? I haven't seen that because everything looks a void...
The validity is guaranteed by the construction of the class instances, thus as long as the texture is in the scope it (should) be valid and the same applies to sprites. Keep in mind though that the texture needs to be kept alive when drawing a sprite (but the application won't crash if it isn't).

Try to use the debugger to find out what exactly goes wrong. Also you should say which version of SFML with which compiler you used.
And to mske sure it's not directly related to ypur code, you should always provide a minimal and complete example. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

timo777

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Unresolved external symbol "public: static class sf::Image *
« Reply #8 on: December 25, 2012, 12:35:17 pm »
Okay, the problem was I used a function to request the texture from the handler so he couldn't retrieve it on draw. I fixed it and it works fine now.