错误 LNK2001:未解析的外部符号“公共:静态类 sf::RenderStates const sf::RenderStates::Default" [英] error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default"
问题描述
代码如下:
引擎.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();
}
}
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;
}
如果我删除 wd.draw(player);从 Engine.cpp 中,不会发生此错误,似乎我无法绘制任何东西,我是否定义了默认构造函数而不调用它?还是我以错误的方式传递参数?请解释为什么会出现这个错误并给我一个合理的解决方案,感谢进一步的回答.
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 内存、geforce gtx850M 4GB 视频内存、Windows 8.1.
OBS: SFML 2.1, Microsoft Visual Studio 2013, i7, 8gb ram, geforce gtx850M 4gb video ram, Windows 8.1.
推荐答案
您应该将 *.lib 文件的文件名添加到 vs 的链接器中.
You should add your file names of *.lib files to vs' linker.
步骤:
- 打开您的项目属性页面.(在 vs 中按 Alt+F7).
- 展开配置属性".
- 展开链接器".
- 您将在链接器"下找到输入"项,然后单击输入".
- 在右侧,您会找到一项附加依赖项".
- 在此处添加您的 lib 文件名.(例如 lib1.lib;lib2.lib...,用分号分隔库).
这篇关于错误 LNK2001:未解析的外部符号“公共:静态类 sf::RenderStates const sf::RenderStates::Default"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!