错误 LNK2001:未解析的外部符号"public: static class sf::RenderStates const sf::RenderStates::Default"

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

本文关键字:sf RenderStates public static class Default const 符号 LNK2001 外部 错误      更新时间:2023-10-16

这是代码:

发动机.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;
};

引擎.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();
    }
}

主.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;
}

如果我从引擎中删除 wd.draw(player(; .cpp,则不会发生此错误,似乎我无法绘制任何内容,我是否定义了默认构造函数而不调用它?还是我以错误的方式传递论点?请解释为什么会发生此错误并给我一个合理的解决方案,感谢您的进一步回答。

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

您应该将 *.lib 文件的文件名添加到 vs' 链接器中。

步骤:

  1. 打开项目属性页。按 Alt+F7 在 vs( 中。
  2. 展开"配置属性"。
  3. 展开"链接器"。
  4. 您将在"链接器"下找到"输入"项,然后单击"输入"。
  5. 在右侧,您将找到"其他依赖项"项。
  6. 在此处添加您的库文件名。(例如lib1.lib;lib2.lib...,用分号分隔库(。