user3995080
user3995080

Reputation:

error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default"

Here's the code:

Engine.h

#include <SFML/Audio.hpp>
#include <SFML/Config.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

class Engine
{
public:
    Engine(sf::RenderWindow & wd);
    void run(sf::RenderWindow & wd);

    sf::Sprite player;
    sf::Texture playerTexture;

};

Engine.cpp

#include "Engine.h"

Engine::Engine(sf::RenderWindow & wd) : player(), playerTexture()
{

}

void Engine::run(sf::RenderWindow & wd)
{
    if (!playerTexture.loadFromFile("image/char.png")) {}
    player.setTexture(playerTexture);

    while (wd.isOpen())
    {
        sf::Event event;
        while (wd.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                wd.close();
        }

        wd.clear();
        wd.draw(player);
        wd.display();
    }
}

main.cpp

#include <SFML/Audio.hpp>
#include <SFML/Config.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

#include "Engine.h"

int main()
{
    sf::RenderWindow * wd = new sf::RenderWindow(sf::VideoMode(800, 600), "Lumia");
    Engine * eg = new Engine(*wd);
    eg->run(*wd);

    return EXIT_SUCCESS;
}

if I delete wd.draw(player); from Engine.cpp, this error doesn't occur, it seems like I can't draw anything, am I defining a default constructor and not calling it? Or am I passing arguments in aa wrong way? Please explain me why this error occurs and give me a reasonably solution, thanks for further answers.

OBS: SFML 2.1, Microsoft Visual Studio 2013, i7, 8gb ram, geforce gtx850M 4gb video ram, Windows 8.1.

Upvotes: 2

Views: 7384

Answers (1)

alacy
alacy

Reputation: 5074

You should add your file names of *.lib files to vs' linker.

Steps:

  1. Open your project Property pages.(Press Alt+F7 in vs).
  2. Expand "Configuration Properties".
  3. Expand "Linker".
  4. You will find item "Input" under "Linker" and click the "Input".
  5. On the right side,you will find a item "Additional Dependencies".
  6. Add your lib file names here.(for example lib1.lib;lib2.lib...,separate the libraries with semicolon).

Upvotes: 2

Related Questions