I'm new to SFML but I installed on Windows 11 and tried a sample program and it worked first try.
Impressive.
I installed on new minimal install of Ubuntu 20.04 with only gcc and sfml added and it failed. I suspect it's some trivial problem but I cannot find it after extensive searches.
I also tried it on Ubuntu 24.04 with the same result.
Here's the compile command and the error I get:
------------------------------
jimbrown@Ub20:~$ g++ -O0 -g3 -Wall "sfmltest.cpp"
sfmltest.cpp: In function ‘int main(int, char**)’:
sfmltest.cpp:14:36: error: qualified-id in declaration before ‘event’
14 | while (const std::optional event = window.pollEvent())
| ^~~~~
sfmltest.cpp:16:17: error: ‘event’ was not declared in this scope
16 | if (event->is<sf::Event::Closed>())
| ^~~~~
sfmltest.cpp:16:46: error: expected primary-expression before ‘)’ token
16 | if (event->is<sf::Event::Closed>())
|
------------------------------
Here's the program - mostly from a sample on the web with some added undef's because of a suggetion I found while searching:
#undef Status
#undef None
#undef BadRequest
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
int main(int argc, char** argv) {
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();
}
} //end main