I know this question has been asked before but following the answer or other online resources I came across yielded nothing.
I've built SFML from source for Windows using CMAKE GUI and mingw32-make. I've changed it from making shared to static libraries. On the SFML site, it states that the dependencies are included under Windows but after I added the files to my project and changed the CMakeList to include SFML it gives an error that SFML is found but its dependencies are not.
SFML found but some of its dependencies are missing (FreeType OpenAL VorbisFile VorbisEnc Vorbis Ogg FLAC)
To include SFML I have the following in CMake:
set(SFML_STATIC_LIBRARIES TRUE) # I've build static libraries
set(SFML_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/SFML/cmake) # Contains the CMake files for SFML
find_package(SFML 2.5 COMPONENTS system window graphics network audio REQUIRED) # Using v2.5.1
set(SFML_LIBS
libsfml-audio-s
libsfml-graphics-s
libsfml-main
libsfml-network-s
libsfml-system-s
libsfml-window-s
)
target_link_libraries(${PROJECT_NAME} ${SFML_LIBS})
I've tried to add the dependencies in CMake:
set(SFML_DEPENDENCIES
libFLAC
libfreetype
libogg
libopenal32
libvorbis
libvorbisenc
libvorbisfile
)
target_link_libraries(${PROJECT_NAME} ${SFML_LIBS} ${SFML_DEPENDENCIES})
But this did not change the outcome.
I've looked through the source files and found the missing libraries in extlibs but copying these does not help (or I've placed them in the wrong place) Do I need to get the dependencies myself and where should I put these?
The issue was that after building it and moving it over to the project I placed the files in the wrong place. So it could not find them.
Here is how I did it. I built it using CMake and mingw32-make from the source, changing the settings from dynamic to static built. After this, I moved the files to a folder in my project. Built statically, you also need to get the required files from the source and place them in the lib folder. To add it in the project I changed the CMakeList.txt in my project to the following:
cmake_minimum_required(VERSION 3.23)
set(CMAKE_CXX_STANDARD 23)
# Setup
project(main) # Must match the main file name
set(EXECUTABLE_NAME "Test") # Executable name
set(project_headers
#logger.hpp # Custom logger
)
set(project_sources
${PROJECT_NAME}.cpp
#logger.cpp # Custom logger
)
include_directories(
# dirs to include
ext/SFML/include/
)
link_directories(
# dirs to link
ext/SFML/lib/
)
# SFML
set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR ext/SFML/lib/cmake)
find_package(SFML 2.5 COMPONENTS system window graphics network audio REQUIRED)
set(SFML_LIBS
sfml-audio-s
sfml-graphics-s
sfml-network-s
sfml-system-s
sfml-window-s
)
# Build
add_executable(${EXECUTABLE_NAME} ${PROJECT_NAME} ${project_sources} ${project_headers})
target_link_libraries(${PROJECT_NAME} ${SFML_LIBS})
EDIT Forgot the dependencies:
set(SFML_DEPENDENCIES
opengl32 # window, graphics
winmm # window, system
gdi32 # window
freetype # graphics
openal32 # audio
FLAC # audio
vorbis # audio
vorbisfile # audio
vorbisenc # audio
ogg # audio
ws2_32 # network
)
target_link_libraries(${PROJECT_NAME} ${SFML_LIBS} ${SFML_DEPENDENCIES}) # SFML first, dependencies second