I'm trying to get started with SFML, and to get everything started I'm doing an incredibly simple program:
#include <iostream>
#include <SFML/Window.hpp>
int main() {
sf::Time t1 = sf::seconds(0.01f);
return 0;
}
But lots of problems are coming up with linking things. When I try to run this program, I get this error:
CMakeFiles\MY_PROJECT.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/usr/CLionProjects/[...]/MY_PROJECT/main.cpp:6: undefined reference to `__imp__ZN2sf7secondsEf'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\MY_PROJECT.dir\build.make:106: MY_PROJECT.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:95: CMakeFiles/MY_PROJECT.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:102: CMakeFiles/MY_PROJECT.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:137: MY_PROJECT] Error 2
Here as much info about relevant files/folders/configs and their contents/locations/etc as I can think of:
CMakeLists.txt
(Top level of project directory)cmake_minimum_required(VERSION 3.17)
project(MY_RPOJECT)
set(CMAKE_CXX_STANDARD 14)
add_executable(MY_PROJECT main.cpp)
set(SFML_ROOT C:/[...]/SFML-2.5.1)
include_directories(C:/[...]/SFML-2.5.1/include)
find_package(SFML REQUIRED audio graphics window network system)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake-modules")
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(MY_PROJECT ${SFML_LIBRARIES})
endif()
# file(COPY assets DESTINATION ${CMAKE_BINARY_DIR})
if(WIN32)
file(GLOB BINARY_DEP_DLLS "${SFML_INCLUDE_DIR}/.../bin/*.dll")
file(COPY ${BINARY_DEP_DLLS} DESTINATION ${CMAKE_BINARY_DIR})
endif()
FindSFML.cmake
(in both "cmake-modules" folder which is at top level of project directory and in C:\Program Files\CMake\share\cmake-3.22\Modules)[Contents not shown]
Make: C:\Program Files\mingw64\bin\mingw32-make.exe
C++ Compiler: C:\Program Files\mingw64\bin\g++.exe
Running cmake:Ran in the top level directory of my project
Source code: The top level directory of my project
Where to build binaries: cmake-build (folder in top level directory of my project)
PATHS:Environmental variable paths are linked up to
1) The root folder of my SFML directory
2) bin folder in my SFML directory
3) Root folder of mingw64
4) bin folder of mingw64
SFML info:SFML-2.5.1
GCC 7.3.0 MinGW (DW2) - 32-bit
have tried this with 64 bit too, exact same errorTDM 5.1.0 (32-bit), MinGW Builds 7.3.0 (32-bit), MinGW Builds 7.3.0 (64-bit)
taken directly from SFML download page
The issue I'm running into is trying to make SFML, I have been trying to follow the documentation/tutorial for setting it up for a while but I'm new to this and can't get it working.
The tutorial says that I have to run
cmake -G"MinGW Makefiles" ./build
although I'm a) not sure where to run it and b) it throws a "/build directory not found" error whenever I try it
When running cmake (as per SFML tutorial, I'm doing cmake-gui) and I hit "configure", it doesn't show up with any SFML variables, even though it says it should on the tutorial. It finishes configuring with only CMAKE_BUILD_TYPE, CMAKE_GNUtoMS, CMAKE_INSTALL_PREFIX, and SFML_INCLUDE_DIR coming up as variables. I can hit generate and it successfully generates, but running the project throws the aforementioned error.
Any help would be very appreciated! I am at a complete loss