The problem is not whether you should do it or not, this code should work. If it doesn't, it means that you have an environment issue that must be fixed, otherwise you won't be able to develop anything with SFML.
How did you recompile SFML, what options did you change in CMake?