【发布时间】:2021-03-30 20:06:17
【问题描述】:
所以最近我一直在尝试使用 C++ 和 SFML,因为它似乎非常适合我打算做的项目,但是,即使编译用于检查我的安装的示例代码,我也遇到了困难。错误列表显示'event' uses undefined class 'sf::Event'。
我非常密切地遵循安装 SFML 的教程,尝试将 SFML 动态和静态链接到我的项目,并直接包含此类所需的 .hpp 文件,但令我沮丧的是,我仍然无法解决这个问题.我知道这一定是我安装的一个根本问题,但我不知道是什么。
这里是代码:
#include <C:\Users\xxx_gpo4v3f\Documents\SFML-2.5.1-windows-vc15-64-bit\SFML-2.5.1\include\SFML\Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
谢谢!
编辑:
原来的错误:
Severity Code Description Project File Line Suppression State
Error C2664 'bool sf::Window::pollEvent(sf::Event &)': cannot convert argument 1 from 'int' to 'sf::Event &' Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.cpp 13
Error (active) E0070 incomplete type is not allowed Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.cpp 12
Error (active) E0070 incomplete type is not allowed Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.cpp 15
Error (active) E0070 incomplete type is not allowed Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.cpp 15
Error C2079 'event' uses undefined class 'sf::Event' Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.cpp 12
Error C2027 use of undefined type 'sf::Event' Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.cpp 15
Error C2065 'Closed': undeclared identifier Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.cpp 15
Event.hpp 的完整错误代码:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (??1RenderWindow@sf@@UAE@XZ) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (??0VideoMode@sf@@QAE@III@Z) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall sf::String::String(char const *,class std::locale const &)" (??0String@sf@@QAE@PBDABVlocale@std@@@Z) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: void __thiscall sf::Window::close(void)" (?close@Window@sf@@QAEXXZ) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: bool __thiscall sf::Window::isOpen(void)const " (?isOpen@Window@sf@@QBE_NXZ) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: bool __thiscall sf::Window::pollEvent(class sf::Event &)" (?pollEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: void __thiscall sf::Window::display(void)" (?display@Window@sf@@QAEXXZ) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (??0Color@sf@@QAE@EEEE@Z) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: virtual __thiscall sf::Shape::~Shape(void)" (??1Shape@sf@@UAE@XZ) referenced in function "public: virtual __thiscall sf::CircleShape::~CircleShape(void)" (??1CircleShape@sf@@UAE@XZ) Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: void __thiscall sf::Shape::setFillColor(class sf::Color const &)" (?setFillColor@Shape@sf@@QAEXABVColor@2@@Z) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall sf::CircleShape::CircleShape(float,unsigned int)" (??0CircleShape@sf@@QAE@MI@Z) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: void __thiscall sf::RenderTarget::clear(class sf::Color const &)" (?clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: void __thiscall sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates const &)" (?draw@RenderTarget@sf@@QAEXABVDrawable@2@ABVRenderStates@2@@Z) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (??0RenderWindow@sf@@QAE@VVideoMode@1@ABVString@1@IABUContextSettings@1@@Z) referenced in function _main Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2001 unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B) Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK2001 unresolved external symbol "public: static class sf::Color const sf::Color::Green" (?Green@Color@sf@@2V12@B) Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Gravity1\Main.obj 1
Error LNK1120 16 unresolved externals Gravity1 C:\Users\xxxx_gpo4v3f\source\repos\Gravity1\Debug\Gravity1.exe 1
【问题讨论】:
-
从外部解决这个问题会很困难。
Eventdeclared 类在哪里?它需要在您包含的头文件中,或者在该 [...] 包含的文件中。它必须与其他类位于同一sf命名空间中,并且不得通过任何预处理器符号欺骗将其排除在编译之外(在Event之前查找#define或#ifdef) -
在您的问题中包含完整的错误消息。
-
如果您添加
#include <SFML/Window.hpp>可能吗?或者只是为了确定#include <SFML/Window/Event.hpp>? -
@Hyperil 这应该回答了新问题:stackoverflow.com/questions/12573816/…
标签: c++ visual-studio sfml