错误 LNK2001:未解析的外部符号"public: static class 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();
}
}
主.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' 链接器中。
步骤:
- 打开项目属性页。按 Alt+F7 在 vs( 中。
- 展开"配置属性"。
- 展开"链接器"。
- 您将在"链接器"下找到"输入"项,然后单击"输入"。
- 在右侧,您将找到"其他依赖项"项。
- 在此处添加您的库文件名。(例如lib1.lib;lib2.lib...,用分号分隔库(。
相关文章:
- 使用 sf::Text 数组时崩溃
- 尝试将 sf::Texture* 推送到 std::vector 时出错
- 为什么 sf::Text 显示点而不是数字?
- sf::文本不显示?
- sf::Windows上的音乐:api-ms-win-crt-locale-l1-1-0.dll:无法打开共享对象文件
- 如何将sf::RenderWindow传递给另一个函数
- 当我尝试绘制 sf::Text 对象时,SFML 中的分段错误
- 重载运算符时出错<在 sf::Vector 中
- 声明 sf::SoundBuffer 会导致程序在终止时崩溃
- 正在加载 sf::图片来自 QDialog
- SFML 中的分段错误 调用 sf::窗口::关闭后
- 未解决的外部符号sf ::带有SFML的时间
- crtdbg 在使用 sf::Text::setOutlineThickness 时转储内存泄漏
- sf::声音函数会导致链接器错误
- SFML sf::Mouse::getPosition 方法无法编写正确的参数
- SF :: Renderwindow的destrutor被检测到的堆叠粉碎
- 为什么我的SFML将SF ::纹理作为参数传递到函数时会不断崩溃
- OpenGL equivalent of DirectX renderstates
- SFML/C++ 闪烁命中效果 sf::精灵
- 错误 LNK2001:未解析的外部符号"public: static class sf::RenderStates const sf::RenderStates::Default"