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

Author Topic: [SOLVED] Sprite draw unresolved externals  (Read 3444 times)

0 Members and 1 Guest are viewing this topic.

iamsickinmymind

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
[SOLVED] Sprite draw unresolved externals
« on: March 01, 2018, 04:10:33 pm »
Hi there,
While declaring code, I got two errors - Unresolved external symbol and 1 unresolved externals. I see that the first causes the second one. The 'graphics' folder is located in the Project Location:
C:\Users\cpp_shared\documents\visual studio 2015\Projects\test004\graphics

SFML libraries declared in Project->Properties->Debug->Linker->Input:
sfml-graphics-d.lib;sfml-window-d.lib;sfml-system-d.lib;sfml-network-d.lib;sfml-audio-d.lib;

I would be very happy if anyone could help me :)

Code:

// SFML_default.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <SFML/Graphics.hpp>

using namespace sf;


int main()
{
        VideoMode vm(1280, 720);

        RenderWindow window(vm, "TEST", Style::Default);

        Texture backgroundTexture;

        backgroundTexture.loadFromFile("graphics/background");

        Sprite backgroundSprite;

        backgroundSprite.setTexture(backgroundTexture);

        backgroundSprite.setOrigin(0, 0);

        while (window.isOpen())
        {
                if (Keyboard::isKeyPressed(Keyboard::Escape))
                {
                        window.close();
                }
        }

        window.clear();

        window.draw(backgroundSprite); //<--|| Here goes the failure

        window.display();
       
        return 0;
}
 
« Last Edit: March 03, 2018, 10:14:40 am by iamsickinmymind »

iamsickinmymind

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Sprite draw unresolved externals
« Reply #1 on: March 01, 2018, 04:24:02 pm »
Since I'm very clever :), I changed Style::Fullscreen to Style::default and I witnessed an error message:


Failed to load image "graphics/background". Reason: Unable to open file

Project path:
C:\Users\cpp_shared\documents\visual studio 2015\Projects\test004\
Image path:
C:\Users\cpp_shared\documents\visual studio 2015\Projects\test004\graphics\

What might be the problem in here?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sprite draw unresolved externals
« Reply #2 on: March 01, 2018, 06:12:33 pm »
You should always check the boolean result of loading an image (and most other things too) to see whether it succeeds or fails, rather than just carry on as if it's fine.

The image might be in an unsupported format or you may have the path incorrect. A good way to check both is to specify the image's absolute path. If it still doesn't work (and the absolute path is correct), the image is the problem, and if the does work, your path was the problem.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

iamsickinmymind

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Sprite draw unresolved externals
« Reply #3 on: March 01, 2018, 08:40:50 pm »
You should always check the boolean result of loading an image (and most other things too) to see whether it succeeds or fails, rather than just carry on as if it's fine.

The image might be in an unsupported format or you may have the path incorrect. A good way to check both is to specify the image's absolute path. If it still doesn't work (and the absolute path is correct), the image is the problem, and if the does work, your path was the problem.

Thank you for suggestions.
I did a simple check:
if (!backgroundTexture.loadFromFile("graphics/background2.jpg")) {
                return 1;
        }
 
It returned false. My thoughts are that VS doesn't have sufficient permissions to read the file. But the error appears anyway, despite changed folder.
Am I missing something? Maybe the main reason is that project was created from custom template...

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sprite draw unresolved externals
« Reply #4 on: March 01, 2018, 09:27:48 pm »
Did you try using the absolute path?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

iamsickinmymind

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Sprite draw unresolved externals
« Reply #5 on: March 02, 2018, 09:34:15 am »
Did you try using the absolute path?

I did. Even tried to move file to non-system disc "D", but still failed.
Am I missing any library? Using WIN32 console and 32 libraries mentioned in the original post.

iamsickinmymind

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Sprite draw unresolved externals
« Reply #6 on: March 02, 2018, 01:28:14 pm »
Did you try using the absolute path?

I did the following:

// TIMBER4.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include <iostream>

using namespace sf;


int main()
{
        system("dir");
       
        //Creating object 'vm' of 'VideoMode' class
        VideoMode vm(1280, 720);

        //Creating object 'window' of 'RenderWindow' class
        RenderWindow window(vm, "TIMBER", Style::Default);

        //Setting texture
        Texture textureBackground;
       
        if (!textureBackground.loadFromFile("graphics/background.png"))
        {
                std::cout << "ERROR";
        }

        //Create Sprite and attach a Texture
        Sprite spriteBackground;
        spriteBackground.setTexture(textureBackground);
        spriteBackground.setPosition(0, 0);

        while (window.isOpen())
        {
                if (Keyboard::isKeyPressed(Keyboard::Escape))
                {
                        window.close();
                }

        }

        window.clear();

        //window.draw(spriteBackground);

        window.display();

        return 0;
}
 

Result? Printed out DIR (it's OK so far I can say) and did not print our "ERROR" message. Does it mean that the texture.loadFromFile successfully loaded a texture from the file?

If so, I don't understand why I'm getting the error. If the line '//window.draw(spriteBackground);' is not commented out, the error LNK2001 (unresolved external symbol) appears with message: 'Severity   Code   Description   Project   File   Line   Suppression State
Error   LNK2001   unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)'. So far I understand - the draw fce is not able to process the argument Sprite, am I right?

If so, why is that happening?

iamsickinmymind

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: Sprite draw unresolved externals
« Reply #7 on: March 02, 2018, 01:36:02 pm »
Did you try using the absolute path?

And a little update:

Texture textureBackground;
        textureBackground.loadFromFile("background.png");
        if (!textureBackground.loadFromFile("background.png"))
        {
                std::cout << "ERROR";
        }
        else if (textureBackground.loadFromFile("background.png"))
        {
                std::cout << "FILE FOUND";
        }
 

Cout throws out "FILE FOUND".
Sorry for being such annoying, but I'm really desperate.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: [SOLVED] Sprite draw unresolved externals
« Reply #8 on: March 06, 2018, 09:30:32 pm »
In your file loading test, it's actually loading it a second or maybe third time.
The test is usually just:
if (!texture.loadFromFile("image.png"))
{
    std::cerr << "Failed to load image." << std::endl;
    return EXIT_FAILURE;
}
That way everything else that follows this code knows that the texture loading was successful.


Your problem does sound strange although similar errors have popped up before due to builds so you should probably check it.
Is your SFML a downloaded binary or did you build it yourself from the master source?
Which version of SFML are you using?
If downloaded, is the compiler version of that library identical to the compiler version you are using (not just "similar")?
Are you mixing builds? Using release/debug builds when you're trying to compile in the opposite? Same with 32-bit and 64-bit; they have to match perfectly too.
Are you mixing versions? We've all done it, right? You link the headers of the new version of SFML but forget to update the DLLs (or whatever) that are in your directory. ;D
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything