In case you have been installing SFML with brew (on Mac) you might be needed to link the include and lib sfml directories in the compilation process. You can do that by first find where SFML was installed using,
brew info sfml
which will give you something similar to this
==> sfml: stable 2.6.1 (bottled), HEAD
Multi-media library with bindings for multiple languages
https://www.sfml-dev.org/
/opt/homebrew/Cellar/sfml/2.6.1 (812 files, 12.7MB) *
Poured from bottle using the formulae.brew.sh API on 2023-12-05 at 13:54:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/s/sfml.rb
License: Zlib
==> Dependencies
Build: cmake ✘, doxygen ✘
Required: flac ✔, freetype ✔, libogg ✔, libvorbis ✔
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 782 (30 days), 2,444 (90 days), 5,295 (365 days)
install-on-request: 740 (30 days), 2,311 (90 days), 4,994 (365 days)
build-error: 0 (30 days)
where you can copy the library path /opt/homebrew/Cellar/sfml/2.6.1.
Next, when compiling your main.cpp file, run the following
g++ -I/opt/homebrew/Cellar/sfml/2.6.1/include -L/opt/homebrew/Cellar/sfml/2.6.1/lib -lsfml-graphics -lsfml-window -lsfml-network main.cpp -o prog
-I is for linking the library include directory.
-L is for linking the library lib directory.
-l is for linking the specific files needed (depends on your specific code), for the sfml website example, the graphics, network and window files will do.