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}
)