Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: error: no matching function for call to 'sf::Event::Event()  (Read 2567 times)

0 Members and 2 Guests are viewing this topic.

alpaca1723

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
error: no matching function for call to 'sf::Event::Event()
« on: September 25, 2024, 01:06:17 pm »
Hello, I was following this tutorial to setup SFML on windows with CMake



I downloaded SFML version 2.6.1 from the github repo, and I'm using minGW64, gcc version 13.1.0 with cmake version 3.30.3

and when I try to build the code from the tutorial:

#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();
    }

    return 0;
}

I get the error in the title. Complete log:


C:\workspace\SFML_projects\src\main.cpp: In function 'int main()':
[build] C:\workspace\SFML_projects\src\main.cpp:8:15: error: no matching function for call to 'sf::Event::Event()'
[build]     8 |     sf::Event event;
[build]       |               ^~~~~
[build] In file included from C:/workspace/SFML_projects/external/SFML/include/SFML/Window/WindowBase.inl:28,
[build]                  from C:/workspace/SFML_projects/external/SFML/include/SFML/Window/WindowBase.hpp:614,
[build]                  from C:/workspace/SFML_projects/external/SFML/include/SFML/Window/Window.hpp:32,
[build]                  from C:/workspace/SFML_projects/external/SFML/include/SFML/Graphics/RenderWindow.hpp:36,
[build]                  from C:/workspace/SFML_projects/external/SFML/include/SFML/Graphics.hpp:45,
[build]                  from C:\workspace\SFML_projects\src\main.cpp:1:
[build] C:/workspace/SFML_projects/external/SFML/include/SFML/Window/Event.hpp:306:5: note: candidate: 'template<class TEventSubtype> sf::Event::Event(const TEventSubtype&)'
[build]   306 |     Event(const TEventSubtype& eventSubtype);
[build]       |     ^~~~~
[build] C:/workspace/SFML_projects/external/SFML/include/SFML/Window/Event.hpp:306:5: note:   template argument deduction/substitution failed:
[build] C:\workspace\SFML_projects\src\main.cpp:8:15: note:   candidate expects 1 argument, 0 provided
[build]     8 |     sf::Event event;
[build]       |               ^~~~~
[build] C:/workspace/SFML_projects/external/SFML/include/SFML/Window/Event.hpp:46:7: note: candidate: 'constexpr sf::Event::Event(const sf::Event&)'
[build]    46 | class Event
[build]       |       ^~~~~
[build] C:/workspace/SFML_projects/external/SFML/include/SFML/Window/Event.hpp:46:7: note:   candidate expects 1 argument, 0 provided
[build] C:/workspace/SFML_projects/external/SFML/include/SFML/Window/Event.hpp:46:7: note: candidate: 'constexpr sf::Event::Event(sf::Event&&)'
[build] C:/workspace/SFML_projects/external/SFML/include/SFML/Window/Event.hpp:46:7: note:   candidate expects 1 argument, 0 provided
[build] mingw32-make[2]: *** [CMakeFiles\sfml_setup.dir\build.make:76: CMakeFiles/sfml_setup.dir/src/main.cpp.obj] Error 1
[build] mingw32-make[1]: *** [CMakeFiles\Makefile2:224: CMakeFiles/sfml_setup.dir/all] Error 2
[build] mingw32-make: *** [Makefile:135: all] Error 2
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/workspace/SFML_projects/build --config Debug --target all -j 10 -- exited with code: 2
[driver] Build completed: 00:00:06.907
[build] Build finished with exit code 2


I know it's probably some dumb stuff, but can someone help? Fyi, if I don't use the event and I just show the window, it works fine, I just can't close it.

The CMakeLists.txt is

cmake_minimum_required(VERSION 3.30)
project(sfml_setup)

set(SFML_STATIC_LIBRARIES TRUE)
set(BUILD_SHARED_LIBS TRUE)

file(GLOB SOURCES "src/*.cpp")

add_executable(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE include)

# SFML
add_subdirectory(external/SFML)
target_include_directories(${PROJECT_NAME} PRIVATE external/SFML)
target_link_libraries(${PROJECT_NAME} PUBLIC sfml-audio sfml-graphics sfml-main sfml-network sfml-system sfml-window)

add_custom_command( # copy dynamic libs to bin directory
    TARGET ${PROJECT_NAME}
    COMMAND ${CMAKE_COMMAND} -E copy_directory
    ${CMAKE_BINARY_DIR}/external/SFML/bin
    ${CMAKE_BINARY_DIR}
)

« Last Edit: September 25, 2024, 01:08:23 pm by alpaca1723 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: error: no matching function for call to 'sf::Event::Event()
« Reply #1 on: September 25, 2024, 02:49:39 pm »
I downloaded SFML version 2.6.1 from the github repo
That's what you thought you did, but you actually seem to have downloaded master, which is SFML 3 that has changed quite a few things. ;)

To get the latest SFML 2 version, you can checkout the 2.6.x branch as mentioned in the readme.

If you want to update to SFML 3, you can read the migration guide.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

alpaca1723

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: error: no matching function for call to 'sf::Event::Event()
« Reply #2 on: September 25, 2024, 02:53:51 pm »
Welp now I feel dumb. Thank you very much!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: error: no matching function for call to 'sf::Event::Event()
« Reply #3 on: September 25, 2024, 03:12:07 pm »
No worries. It's one of the major down sides to YouTube tutorials. Once things change, their content can't be easily updated.

If you want a better recommended starting point, you can take a look at the SFML CMake template: https://github.com/SFML/cmake-sfml-project
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything