So recently I've been experimenting with C++ and SFML, as it seems perfect for a project I am aiming to do, however, I have been having difficulties even compiling the example code used to check my installation. the error list says that says 'event' uses undefined class 'sf::Event'
.
I have followed, very closely, the tutorial for the installation of SFML, tried both dynamically and statically linking SFML to my project, and directly including the .hpp file needed for this class, but to my dismay, I can still not fix this issue. I know it must be a fundamental issue with my installation, but I can not figure out what.
Here is the code anyway:
#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();
}
Thanks!
EDIT:
Original error:
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
Full error code with 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