Help with getting SFML for C++ set up for a project?
(lemmy.world)
submitted 3 days ago* (last edited 1 day ago)
by ComicalMayhem@lemmy.world
to c/nostupidquestions@lemmy.world
I followed the directions on SFML's website for installation and usage via CMake. Cloned the git repo and ran cmake -B build cmake --build build. Everything went fine, but when I try to compile the test program with g++, it fails with a few different errors.
Here's the errors:
src/main.cpp: In function ‘int main()’:
src/main.cpp:11:45: error: qualified-id in declaration before ‘event’
11 | while ( const std::optional event = window.pollEvent() )
| ^~~~~
src/main.cpp:13:30: error: ‘event’ was not declared in this scope
13 | if ( event->is<sf::Event::Closed>() )
| ^~~~~
src/main.cpp:13:59: error: expected primary-expression before ‘)’ token
13 | if ( event->is<sf::Event::Closed>() )
| ^
And the main file:
#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() )
{
while ( const std::optional event = window.pollEvent() )
{
if ( event->is<sf::Event::Closed>() )
window.close();
}
window.clear();
window.draw( shape );
window.display();
}
}
It should work to my knowledge, I think. I mean, this is straight from SFML's github and tutorial page on their website, so it should be functional as-is once the cmake stuff is handled, right?
EDIT: Figured it out. Had to build the executable from the build folder via make.